问题
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