您可以在接入点上计数已连接的设备,并且可以在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; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)