Getting the MAC addresses of in-range WiFi networks

三世轮回 提交于 2021-01-28 21:08:05

问题


Is it possible to retrieve the MAC addresses of all available WiFi networks? I know you can do it for the network you're currently connected to:

WifiManager wifiMan = (WifiManager) this.getSystemService(
            Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
String macAddr = wifiInf.getMacAddress();

But is it also possible for networks you're not connected to?

Edit: Is it at all possible under the OSI model (http://en.wikipedia.org/wiki/OSI_model) ? It seems like the MAC Address is in layer 2, so it would not be accessibe before having an active connection, right?


回答1:


It's possible to retrieve the MAC addresses(BSSIDs) of in-range WiFi access points (they might be part of one larger network).

mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
mWifiManager.startScan();
List<ScanResult> results = mWifiManager.getScanResults();
for (ScanResult result : results) 
{
    System.out.println("Access Point MacAddr:" + result.BSSID);         
}


来源:https://stackoverflow.com/questions/19668101/getting-the-mac-addresses-of-in-range-wifi-networks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!