Can anyone explain or show how to get the IP address of a computer (or other device) that's connected through the phone's portable WI-FI hotspot?
I tried the following code from here
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;
}
But that only returns the default gateway.
I also found another example here on SO, and it might just be the solution, but I don't know how to apply it to my situation. Specifically I cannot see where the IP address is in that piece of code.
The following code will give you the ip adrress & other details of the wifi enabled devices connected to the the android hotspot device
Main.java
ClientScanResult.java
}
WIFI_AP_STATE.java
WifiApManager.java
Check your arp table for the wlan interface.
cat /proc/net/arp
at the command line.Though the answer if given, but in case anyone is interested in direct answer:
Also as per my understanding (didn't try by myself), if you are using aysntask and need to do on worker thread(won't work on main thread), this process can also be used. Either use method to find hotspotinterface or directly use _hotspotInterface as "wlan0"
To find hotspot I used this method(though not very good example)