Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find LAN ip address of android device?

Tags:

android

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,

like image 551
Ahmed Avatar asked Nov 18 '12 00:11

Ahmed


1 Answers

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) {}
like image 134
ariefbayu Avatar answered Oct 13 '22 00:10

ariefbayu