Is there a way through which I can get IP address of both WiFi and cellular network in Android simultaneously.I tried using many examples but was able to get Address of only WiFi network and not cellular network.I have enabled both WiFi and cellular network and device is having Internet access through WiFi.
Here is the code which I am using to get the IP address:
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(); Log.i("Here is the Address",ipAddress); } } } } catch (SocketException ex) { }
Is it possible to get IP address of cellular network when device is connected to WiFi.If yes how is that feasible.
Find the page in your router web interface that lists the devices connected to your router. For NETGEAR routers, click BASIC > Attached Devices. Some models might use a slightly different menu label, like Device Manager. A Device Name and IP Address displays for each connected device.
Yes the WiFi and cellular connection have separate IP addresses. You can check your IP address in settings > about phone. You can also check your public IP address by going to a website, e.g. https://www.whatismyip.com/.
Whenever you enable WiFi on your device AND have an active connection to a WiFi network, your mobile data is temporarily disabled, no matter if you have enabled it manually or not. The setting "Mobile data on/off" is only taken into consideration if you have no active WiFi connection.
Some custom ROMs have an option to keep the mobile connection alive when you connect to a WiFi (so in case you lose your WiFi connection, it switches to mobile faster), but still, the WiFi connection is used.
Conclusion: You cannot get both IP addresses as you cannot have both WiFi and mobile network on (and if you can, you only use WiFi actively)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With