Hi i am trying to find all devices connected to My WIFI Router from android and ,i need to device Mac address and local ip address of each device (Including iOT Devices) , right now , i am trying to find from ARP cache table . but sometime in the scan some devices are missing , it is not so accurate .
My Code :
List<LocalDeviceInfo> devicesInfos = new ArrayList<>();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = bufferedReader.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null && splitted.length >= 4) {
String ip = splitted[0];
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
LocalDeviceInfo thisNode = new LocalDeviceInfo(ip, mac);
devicesInfos.add(thisNode);
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Print Description
for (LocalDeviceInfo devicesInfo :devicesInfos)
{
System.out.print("✅");
System.out.println("IP : "+devicesInfo.getIp());
System.out.println("Mac : "+devicesInfo.getMacAddress());
}
How can i scan all devices (IP address and Mac address) in android accurately .