Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting MAC address of Android Wi-Fi Hotspot/tethering/AP

I could get the MAC address of the Wi-Fi interface in Android by:

final WifiInfo wi = wm.getConnectionInfo();
String mac = wi.getMacAddress();

However, I realized, that when the Wi-Fi acts as wireless access point (router) (a.k.a. Hotspot or tethering or AP), the MAC address is no longer the same. I could know that from adb shell ip addr show.

When the Wi-Fi connects to a network, adb shell ip addr show displays:

10: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether a0:0b:ba:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.25/24 brd 192.168.1.255 scope global wlan0
    inet6 fe80::a20b:baff:fee0:73c7/64 scope link 
       valid_lft forever preferred_lft forever

However when it acts as an access point,

10: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:1a:11:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.1/24 brd 192.168.43.255 scope global wlan0

So the MAC addresses differ.

I wonder how do I get a MAC address of the Wi-Fi access point (02:1a:11:xx:xx:xx) from Java code?

like image 219
Randy Sugianto 'Yuku' Avatar asked Oct 01 '22 22:10

Randy Sugianto 'Yuku'


1 Answers

This is a bug or feature in Android. Everytime you start an AP/Wlan tethering a random mac address is generated until you stop the service.

This is reported here in 2011 so I don't think this will change anytime soon https://code.google.com/p/android-wifi-tether/issues/detail?id=1104

Update 2018: It seems that they officially announced this as a security feature: https://source.android.com/devices/tech/connect/wifi-mac-randomization

like image 185
Patrick Favre Avatar answered Oct 18 '22 00:10

Patrick Favre