已连接的热点设备列表



我想检索连接到我的智能手机WiFi热点的所有设备的IP地址。在Android 10及以下版本中,我可以通过执行以下代码获得这个列表:

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ip neigh show");
proc.waitFor();
int exit = proc.exitValue();
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
BufferedReader buffer = new BufferedReader(reader);
String line;
while ((line = buffer.readLine()) != null) {
String[] splits = line.split(" ");
if (splits.length < 4) {
continue;
}
if(!splits[0].contains("192.168.43.")) {
Log.d("IP", splits[0]);
continue;
}
}

然而,似乎IP命令不再在Android 11中工作(https://developer.android.com/training/articles/user-data-ids#mac-11-plus)

The ip command does not return information about interfaces.

在Android 11中是否有其他方法获取已连接客户端的IP地址?

就在今天早上我尝试了命令"ip neigh show"在Android 11手机上使用Termux应用程序,它工作了,给了我邻居的结果....

考虑到Android 10 +不允许你访问"/proc/net/arp"文件了。支持安卓11、三星S10和三星M12。

最新更新