简体   繁体   English

Java中来自远程客户端的本地Net IP地址

[英]Local Net Ip Address from a Remote Client in java

Does anyone know how to get the Local Net Ip Address from a Remote Client in java? 有谁知道如何在Java中从远程客户端获取本地IP地址?

thx 谢谢

Is this what you are looking for? 这是你想要的?

InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress(); // Get IP Address
String hostname = addr.getHostName(); // Get hostname

That gets the IP of the machine the code is running on. 那获得了运行代码的机器的IP。

Assuming you mean getting the local IP address of a client running behind NAT, you can only do that with the client's cooperation, meaning you have to send it yourself. 假设您要获取在NAT之后运行的客户端的本地IP地址,则只能在客户端的配合下完成此操作,这意味着您必须自己发送它。

What do you need it for anyway? 无论如何,您需要什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM