How to get the LAN IP of a client using Java?
Posted
by Henrik
on Stack Overflow
See other posts from Stack Overflow
or by Henrik
Published on 2010-05-16T20:10:53Z
Indexed on
2010/05/16
20:20 UTC
Read the original article
Hit count: 253
How can i get the LAN IP-address of a computer using Java? I want the IP-address which is connected to the router and the rest of the network.
I've tried something like this:
Socket s = new Socket("www.google.com", 80);
String ip = s.getLocalAddress().getHostAddress();
s.close();
This seem to work on some cases, but sometimes it returns the loopback-address or something completely different. Also, it requires internet connection.
Does anyone got a more accurate method of doing this?
© Stack Overflow or respective owner