Saturday, September 17, 2011

Get Ip Address of device

Below function returns the Ip Address of Android Device
*******************************************************

public String getLocalIpAddress() {
try {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e(LOG_TAG, ex.toString());
}
return null;
}

3 comments:

  1. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
    Vee Eee Technologies

    ReplyDelete
  2. Excellent information on Android Development and thanks for sharing this information.

    ReplyDelete
  3. Nice information. I had checked my External ip address using this site IP-Details.com

    ReplyDelete