您可以找到路由器的Mac地址,并将其用作唯一标识路由器的基础 .
您可以通过检查Android设备ARP表并比较您连接的路由器IP来执行此操作 . 这里可以显示一个例子:
提取的相关代码:
/**
* Try to extract a hardware MAC address from a given IP address using the
* ARP cache (/proc/net/arp).
*
* We assume that the file has this structure:
*
* 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) {