ln e
ln e

Reputation: 1135

Getting the MAC addresses of in-range WiFi networks

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?

Upvotes: 1

Views: 2399

Answers (1)

ln e
ln e

Reputation: 1135

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);         
}

Upvotes: 2

Related Questions