简体   繁体   中英

How to find LAN ip address of android device?

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,

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) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM