25

Can my Android app find the MAC address of the Wifi access point it is connected to?

The docs for android.net.wifi.WifiInfo getMacAddress() don't provide any details.

See http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getMacAddress().

I'm assuming this is the Mac address of my phone. Can I find the Mac address of the access point?

aminography
  • 21,986
  • 13
  • 70
  • 74
Michael Levy
  • 13,097
  • 15
  • 66
  • 100
  • Marc, can you please post that as an answer so I can accept it? You are right on target, BSSID is the AP Mac address in infrastructure mode - http://en.wikipedia.org/wiki/Service_set_(802.11_network)#Basic_service_set_identifier_.28BSSID.29. And Android exposes android.net.wifi.WifiInfo getBSSID() – Michael Levy May 19 '11 at 19:50
  • Thanks Michael, glad to hear it's working for you. – Marc Bernstein May 20 '11 at 23:26

4 Answers4

22

getBSSID() of WifiInfo class will return MAC address of remote access point.

BSSID explained here.

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
  • Thanks. I just figured that out after Marc commented on my question above. – Michael Levy May 19 '11 at 20:21
  • 1
    Not sure what's going on, but I receive two different addresses when trying to fetch BSSID from two different devices connected to the same wifi router. Any ideas? – Urban Apr 02 '15 at 22:55
  • BSSID is not the MAC address of the AP, it is the MAC address of the ssid. Detailed explanation can be found in https://arubanetworkskb.secure.force.com/pkb/articles/FAQ/How-is-the-BSSID-derived-from-the-Access-Point-ethernet-MAC-address – Anuruddha Aug 01 '16 at 12:09
  • @Anuruddha Maybe you can verify again but BSSID is the mac address of the current access point as per the [documentation](https://developer.android.com/reference/android/net/wifi/WifiInfo.html#getBSSID()). – Wahib Ul Haq Oct 09 '18 at 14:15
13

The following method will return the MAC address of the access point, null if there is no network currently connected.

public String getMacId() {

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    return wifiInfo.getBSSID();
}
Tamal Samui
  • 738
  • 10
  • 14
4

Check out the application "Network Info II" from the Android Market. It does show the MAC address, but I'm not sure if this is still the phone's MAC. It also shows the BSSID, which has the same format as a MAC address so perhaps is what you're looking for.

Marc Bernstein
  • 11,423
  • 5
  • 34
  • 32
2

I'm fairly sure that getMacAddress(), is, as you suspected for the Local Device.

If you can get the IP of the router/gateway/accesspoint, then you might be able to use the code in this post: https://web.archive.org/web/20160308014312/http://www.flattermann.net/2011/02/android-howto-find-the-hardware-mac-address-of-a-remote-host/ to do your bidding. Good luck!

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Joseph Redfern
  • 939
  • 1
  • 6
  • 13
  • 1
    I was just about to post the same link. Funny what Google can turn up. ;-) @Michael: android.net.DhcpInfo.gateway might be what you need for the IP address of the AP – Squonk May 19 '11 at 19:50
  • Sadly this approach doesn't work on Android 10 or newer. – Emil S. Dec 02 '19 at 08:50