【发布时间】:2015-10-30 11:14:37
【问题描述】:
我正在尝试构建一个软件来检查哪些设备连接到我的家庭网络,并每 10 分钟左右返回这些设备的 MAC 地址列表。
我的方法是 ping 网络上所有可能的 IP 地址,然后调用“arp -a”。
以下代码用于查找设备是否在 IP 地址上注册,但我不知道如何从中获取 MAC 地址。
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);
}
有什么建议吗?
【问题讨论】:
标签: java ping router mac-address arp