我已经看到了从打开热点的Android设备上运行的应用程序获得成功连接的热点客户端的MAC地址的解决方案。但是,我没有看到一个给出连接失败的热点客户端的MAC地址(即尝试连接到热点,但由于身份验证失败而无法获得IP地址)。
我之所以寻找这样一个失败的热点客户端的MAC地址,是因为我想注意附近的Wifi设备。然后我可以识别附近的人,类似于广告系统。我用的是普通的安卓手机,而他们用的是专门的硬件。
我不能期望一个成功的热点连接,因为如果我试图用与用户已经设置的身份验证配置不同的方式打开热点,Android热点设备会崩溃并重新启动。Android将其检测为某些系统违规并重启。这也不是一种理想的方法,因为我更愿意保持热点配置不变。这是我希望获得失败客户的另一个原因。
有谁知道如何做到这一点吗?谢谢。
请看这个
public static String getMACAddress(String interfaceName) {
try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface
.getNetworkInterfaces());
for (NetworkInterface intf : interfaces) {
if (interfaceName != null) {
if (!intf.getName().equalsIgnoreCase(interfaceName))
continue;
}
byte[] mac = intf.getHardwareAddress();
if (mac == null)
return "";
StringBuilder buf = new StringBuilder();
for (int idx = 0; idx < mac.length; idx++)
buf.append(String.format("%02X:", mac[idx]));
if (buf.length() > 0)
buf.deleteCharAt(buf.length() - 1);
return buf.toString();
}
} catch (Exception ex) {
} // for now eat exceptions
return "";
}