I'm trying to build a software that checks what devices are connected to my home network and return a list of those device's MAC address every 10 minutes or so.
My approach was to ping all of the possible IP addresses on the network and call "arp -a" afterwards.
The following code works to find if a device is registered on an IP address, but I don't know how to get the MAC address from this.
try {
String currentIP = InetAddress.getLocalHost().toString();
String subnet = getSubnet(currentIP);
System.out.println("subnet: " + subnet);
for (int i=1;i<254;i++){
String host = subnet + i;
System.out.println("Checking :" + host);
if (InetAddress.getByName(host).isReachable(timeout)){
System.out.println(host + " is reachable");
try {
Socket connected = new Socket(subnet, port);
}
catch (Exception s) {
System.out.println(s);
}
}
}
}
catch(Exception e){
System.out.println(e);
}
Any suggestions?