Return to Snippet

Revision: 33722
at October 12, 2010 18:57 by cautionsign


Initial Code
public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> 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;
}

Initial URL
http://androidcore.com/android-programming-tutorials/633-how-to-get-the-ip-address-of-your-android-device.html

Initial Description


Initial Title
Android get IP Address

Initial Tags
android

Initial Language
Java