How to find LAN ip address of android device?

android

Solution

NetworkInterface will help you:

String ipAddress = null;
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()) {
                ipAddress = inetAddress.getHostAddress().toString();
            }
        }
    }
} catch (SocketException ex) {}

Problem

If wifi of device is connected, I assume the device has an LAN IP address assigned presumably by a dhcp running on a router. How can find it what's the LAN ip address (not the external ip) on the wifi interface ? Thanks,

Original source