In android, I have found network interface names & IP address associated with that interface by below code.
// Iterate over all network interfaces.
for (Enumeration<NetworkInterface> en =
NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{
NetworkInterface intf = en.nextElement();
// Iterate over all IP addresses in each network interface.
for (Enumeration<InetAddress> enumIPAddr =
intf.getInetAddresses(); enumIPAddr.hasMoreElements();)
{
InetAddress iNetAddress = enumIPAddr.nextElement();
// Loop back address (127.0.0.1) doesn't count as an in-use IP address.
if (!iNetAddress.isLoopbackAddress())
{
sLocalIP = iNetAddress.getHostAddress().toString();
sInterfaceName = intf.getName();
}
}
}
Because of network interface name may vary from manufacturer to manufacturer and also it may vary in different devices of same manufacturer.
How to determine which network interface is for wifi, 3G, 4G(LTE) & VPN in Android?
With this methods you can identify if it's Wifi or Mobile connection:
If it's a mobile connection, you can know more with
info.getSubType()
. Using method like this:Hope it helps you :)