使用 ARP 表,我们可以访问 Android 9 及更早版本中热点连接设备的 IP 和 MAC。现在,从 Android 10 开始,同样的权限被拒绝。请建议我如何在 Android 10 中访问已连接设备的 IP 和 MAC 地址。下面的代码适用于 Android 9 版本,但不适用于 Android 10。
BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] clientInfo = line.split(" +");
if(!clientInfo[3].equalsIgnoreCase("type")) {
String mac = clientInfo[3];
String ip = clientInfo[0];
textView.append("\n\nip: " + ip + " Mac: " + mac);
Log.d("IP : ", ip);
Log.d("Mac : ", mac);
}
}
Run the ip neigh show
命令并处理其输出:
val runtime = Runtime.getRuntime()
val proc = runtime.exec("ip neigh show")
proc.waitFor()
val reader = BufferedReader(InputStreamReader(proc.inputStream))
您以同样的方式分割线路,IP 为 [0],MAC 为 [4]。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)