4

I need to get the netmask and ip from the Android so I can calculate all the IP's within my subnet range.

I've been searching and so far I've found this: Programmatically getting the gateway and subnet mask details

The problem is that it doesn't work for all devices. For instance, it doesn't work in the emulator (any Android version) and it doesn't work either in my Archos 7HT with Android 1.5. It returns 0 for netmask and gateway.

Is there any way to do it? Is there any system file which I could read that contains this info?? (something like this: http://www.flattermann.net/2011/02/android-howto-find-the-hardware-mac-address-of-a-remote-host/).

In my advanced wifi settings I can see these settings, so there must be a way to retrieve them...

Thanks.

Community
  • 1
  • 1
sergi
  • 969
  • 5
  • 14
  • 22

1 Answers1

0

Try with APIs InetAddress and NetworkInterface. Emulator has no WIFI, hence is not possible to get address with Wifi API.

Check this reply

Community
  • 1
  • 1
ruhalde
  • 3,521
  • 3
  • 24
  • 28
  • I can get the IP with InetAddress and NetworkInterface without using WifiManager which is better but I can't get the netmask with InetAddress and NetworkInterface, they don't provide such method. – sergi Aug 20 '11 at 13:13
  • You can use the same NetworkInterface to get the subnet mask by retrieving the addresses for all interfaces and for each of these retrieve the network prefix length. Check here -> http://en.wikipedia.org/wiki/Subnetwork – ruhalde Aug 20 '11 at 14:10
  • I don't actually understand what you mean. I mean, I've got the wlan0 interface with IP 192.168.0.2, how am I supposed to retrieve the network prefix length? – sergi Aug 20 '11 at 14:43
  • I already tried that code but cannot import java.net.InterfaceAddress in Android.. – sergi Aug 20 '11 at 16:28
  • I see why I can't import InterfaceAddress, it's present only since API 9 and I'm with API 3.. – sergi Aug 20 '11 at 16:49