0

I have a small home network, and I'd like to figure out IP-address of the host computer within java (Android) app. There are many advices in the Internet, including Stackoverflow.com, but all advised ways give me 127.0.0.1, in fact IP-adresses in my network are like 192.168.1.x. I know that 127.0.0.x are local addresses within this device, whereas 192.168.1.x are IP within local network. Most advised way is InetAddress.getLocalHost().getHostAddress(), but it also gives 127.0.0.1. Class NetworkInterface was tried too, with the same result.

Any idea will be appreciated, thanks in advance

PS I've found small program find-local-devices.jar, and it works perfectly, giving what I need (192.168.1.x), but there is no source code.

Spectorsky
  • 608
  • 4
  • 23
  • If you ran `InetAddress.getLocalHost().getHostAddress()` of course that gives you `127.0.0.1`. That is the localhost of the Android device. – OneCricketeer Mar 12 '17 at 22:13
  • You could ping everything. You already know your subnet. http://stackoverflow.com/a/7218616/2308683 – OneCricketeer Mar 12 '17 at 22:18
  • Possible duplicate of [How to get IP address of the device from code?](http://stackoverflow.com/q/6064510/5221149) – Andreas Mar 12 '17 at 22:18
  • cricket_007, thanks for a quick reply. Of course, I know my subnet for now, but I'm not sure that this 192.168.1.x remains in future. – Spectorsky Mar 12 '17 at 22:38

0 Answers0