开发者

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?开发者_如何学运维

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.


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.

What do you need it for anyway?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜