Android: How can I get the ip address from android application?

Can I get the ip address from an Android application?

+3
source share
3 answers

I kept this in my bookmark for a while, but did not test it:

http://www.droidnova.com/get-the-ip-address-of-your-device,304.html

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;
}
+3
source

If you use the bind application to connect to data for Android, use a cable to connect to your PC. Find the ad hoc connection and connect. Then right click and select status. This will give you the IP address of the phone. I use the Android application "Barnicle WiFi tether" and use a PC running Windows 7.

+1
source

Source: https://habr.com/ru/post/1774371/


All Articles