(android) how to determine the ip address of connected devices in android hotspot
31,931
You can try this method for getting the list of devices connected to your hotspot. for pingCmd refer this
public ArrayList<String> getArpLiveIps(boolean onlyReachables) {
BufferedReader bufRead = null;
ArrayList<String> result = null;
try {
result = new ArrayList<String>();
bufRead = new BufferedReader(new FileReader("/proc/net/arp"));
String fileLine;
while ((fileLine = bufRead.readLine()) != null) {
String[] splitted = fileLine.split(" +");
if ((splitted != null) && (splitted.length >= 4)) {
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
boolean isReachable = pingCmd(splitted[0]);/**
* Method to Ping IP Address
* @return true if the IP address is reachable
*/
if (!onlyReachables || isReachable) {
result.add(splitted[0]);
}
}
}
}
} catch (Exception e) {
} finally {
try {
bufRead.close();
} catch (IOException e) {
}
}
return result;
}
Author by
user3338304
Updated on July 09, 2022Comments
-
user3338304 almost 2 years
i am writing an android app to control other devices if other devices is connected to my android phone's Wifi hotspot. However, i am unable to determine the ip address of the connected devices (say another android phone). Therefore, i am asking a way to determine the ip address of connected devices in my wifi hotspot. Thank you in advance