如何获得通过电话接入点连接的设备数量?

如何获得通过电话接入点连接的设备数量?,第1张

如何获得通过电话接入点连接的设备数量?

您可以在接入点上计数已连接的设备,并且可以在android的以下链接上获取硬件mac地址:http :
//www.flattermann.net/2011/02/android-howto-find-the-hardware-mac-address-of-
远程主机/

上面链接的代码

public static String getMacFromArpCache(String ip) {    if (ip == null)        return null;    BufferedReader br = null;    try {        br = new BufferedReader(new FileReader("/proc/net/arp"));        String line;        while ((line = br.readLine()) != null) { String[] splitted = line.split(" +"); if (splitted != null && splitted.length >= 4 && ip.equals(splitted[0])) {     // Basic sanity check     String mac = splitted[3];     if (mac.matches("..:..:..:..:..:..")) {         return mac;     } else {         return null;     } }        }    } catch (Exception e) {        e.printStackTrace();    } finally {        try { br.close();        } catch (IOException e) { e.printStackTrace();        }    }    return null;}

或者如果您在代码上遇到问题,请尝试以下代码:

 public ArrayList<InetAddress> getConnectedDevices(String YourPhoneIPAddress) {        ArrayList<InetAddress> ret = new ArrayList<InetAddress>();        LoopCurrentIP = 0;        String IPAddress = "";        String[] myIPArray = YourPhoneIPAddress.split("\.");        InetAddress currentPingAddr;        for (int i = 0; i <= 255; i++) { try {     // build the next IP address     currentPingAddr = InetAddress.getByName(myIPArray[0] + "." +  myIPArray[1] + "." +  myIPArray[2] + "." +  Integer.toString(LoopCurrentIP));     ad = currentPingAddr.toString();   /////////////////     Log.d("MyApp",ad);      //////////////     // 50ms Timeout for the "ping"     if (currentPingAddr.isReachable(50)) {         ret.add(currentPingAddr);         ad = currentPingAddr.toString();        /////////////////         Log.d("MyApp",ad);          //////////////     } } catch (UnknownHostException ex) { } catch (IOException ex) { } LoopCurrentIP++;        }        return ret;    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5430435.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存