![](/img/trans.png)
[英]Communication between Android and a device connected to it over Hotspot
[英]latest connected device list android hotspot
我使用以下代碼來讀取連接的設備IP地址如何獲取通過電話連接的設備數量,但我得到錯誤列表,即列表顯示連接到熱點並且當前已斷開連接的早期設備。 有沒有其他方法來獲得更新列表。 或者如何刷新/ proc / net / arp文件以獲取最新列表
還讀了這個與linux上的arp相關但沒有找到出路的方法。
這對我有用,它將顯示沒有連接的設備及其mac地址
public int getClientList() {
int macCount = 0;
BufferedReader br = null;
String flushCmd = "sh ip -s -s neigh flush all";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(flushCmd, null, new File("/proc/net"));
} catch (IOException e) {
e.printStackTrace();
}
try {
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null) {
// Basic sanity check
String mac = splitted[3];
System.out.println("Mac : Outside If " + mac);
if (mac.matches("..:..:..:..:..:..")) {
macCount++;
/* ClientList.add("Client(" + macCount + ")");
IpAddr.add(splitted[0]);
HWAddr.add(splitted[3]);
Device.add(splitted[5]);*/
System.out.println("Mac : " + mac + " IP Address : " + splitted[0]);
System.out.println("Mac_Count " + macCount + " MAC_ADDRESS " + mac);
Toast.makeText(
getApplicationContext(),
"Mac_Count " + macCount + " MAC_ADDRESS "
+ mac, Toast.LENGTH_SHORT).show();
}
/* for (int i = 0; i < splitted.length; i++)
System.out.println("Addressssssss "+ splitted[i]);*/
}
}
} catch (Exception e) {
}
return macCount;
}
試試吧
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.