问题
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?
回答1:
getBSSID() of WifiInfo
class will return MAC address of remote access point.
BSSID
explained here.
回答2:
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();
}
回答3:
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.
回答4:
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!
来源:https://stackoverflow.com/questions/6063889/can-i-find-the-mac-address-of-my-access-point-in-android