Android 获取已连接热点的设备信息

private static final String IP_CMD = “ip neighbor”;
private void getConnectInfo() {
BufferedReader reader = null;

try {
Process ipProc = Runtime.getRuntime().exec(IP_CMD);
ipProc.waitFor();
if (ipProc.exitValue() != 0) {
throw new Exception(“Unable to access ARP entries”);
}

reader = new BufferedReader(new InputStreamReader(ipProc.getInputStream(), “UTF-8”));
String line;
while ((line = reader.readLine()) != null) {
String[] neighborLine = line.split(“\\s+”);

// We don’t have a validated ARP entry for this case.
if (neighborLine.length <= 4) { continue; } String ipaddr = neighborLine[0]; InetAddress addr = InetAddress.getByName(ipaddr); if (addr.isLinkLocalAddress() || addr.isLoopbackAddress()) { continue; } String macAddress = neighborLine[4]; } } catch (Exception e) { } }

Leave a Reply

Your email address will not be published. Required fields are marked *