How can I programatically get the Ip address, default gateway and port number of the PC to which the android phone is connected in USB Tethering mode, without using WIFI Manager?
I used network interfaces, but it doesnt give me the correct information, is there any other way?
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()) {
address += inetAddress.getHostAddress().toString() ;
}
}
}
Ok here is the round about solution that I reached, from the address received through the network interface, I remove the last section in the address, like 192.168.1.40, i remove 40 and iterate through a loop starting from 192.168.1.0 and find out the port which actually connects. The snippet is below