2
여러분 모두 아시다시피 안드로이드 기기는 전화를 액세스 포인트/핫스팟으로 바꾸는 기능을 제공합니다.전화 액세스 포인트를 통해 연결된 장치 수를 얻으려면 어떻게합니까?
휴대 전화의 무선 인터넷 액세스 포인트에 연결된 장치 수를 프로그래밍 방식으로 얻을 수 있습니까?
여러분 모두 아시다시피 안드로이드 기기는 전화를 액세스 포인트/핫스팟으로 바꾸는 기능을 제공합니다.전화 액세스 포인트를 통해 연결된 장치 수를 얻으려면 어떻게합니까?
휴대 전화의 무선 인터넷 액세스 포인트에 연결된 장치 수를 프로그래밍 방식으로 얻을 수 있습니까?
액세스 포인트에 연결된 장치를 셀 수 그것은 안드로이드에 링크 아래에 하드웨어 MAC 주소를 얻을 수있다 : 위의 링크에서 이 http://www.flattermann.net/2011/02/android-howto-find-the-hardware-mac-address-of-a-remote-host/
코드 :
/**
* Try to extract a hardware MAC address from a given IP address using the
* ARP cache (/proc/net/arp).<br>
* <br>
* We assume that the file has this structure:<br>
* <br>
* IP address HW type Flags HW address Mask Device
* 192.168.18.11 0x1 0x2 00:04:20:06:55:1a * eth0
* 192.168.18.36 0x1 0x2 00:22:43:ab:2a:5b * eth0
*
* @param ip
* @return the MAC from the ARP cache
*/
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;
}
또는 u 코드 시도에 문제가있는 경우 코드 아래 :
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;
}
이것은 작동하지 않습니다. 내 전화기의 AP를 설정하고 내 노트북을 AP에 연결했습니다. 'cat/proc/net/arp'을 실행했을 때, 랩톱의 MAC과 IP가 들어있는 레코드 하나를 보았습니다. 문제는 AP에서 내 랩톱을 연결 해제했을 때 ARP 캐시가 새로 고치지 않고 이전 명령을 실행해도 여전히 한 레코드 만 남았습니다. –
@MridangAgarwalla 내 대답이 업데이트되었습니다! –
내 솔루션을 사용해 보셨습니까? –