Can I find the MAC address of my Access point in Android? - android

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?

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

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

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.

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!

Related

Android WiFi Connection Info

I'm getting wifi connection info this way:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
But, could getConnectionInfo method return null in any case? Android documentation reference say this:
Return dynamic information about the current Wi-Fi connection, if any
is active.
I guess if the device is not connected to any network it will return null, won't it?
Thanks
Yes it will return null, if it is not connected to the wi-fi.
But if you are also checking whether internet is available by using above code, then it is not 100% correct way to do so.
Cause it may happen that your device is connected to wifi but no internet is available. so for that
you have to ping any live site (such as google,facebook, or any other trusted website) and check if the returned status code is 200.
I hope this helps.

how to set My Own android Hotspot Device name

I'm not asking about how to create a WIFIConfiguration
that I want to connect to.
But I'm asking how to set my own Device SSID for my own phone?
private WifiManager obWifiManager;
obWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = obWifiManager.getConnectionInfo();
sendMessage(wifiInfo.getSSID());
The above code has no setter method.
Only getter method. Please help!
I then stumbled upon this article. it said the configuration file is located almost there for any linux OS. There is an SSID setting over there!
So i search on that location but found none!
Probably android put it in a different order / place. Any clue?

Which part of WifiInfo can be used to distinguish every unique access point in a big WLAN?

Which part of WifiInfo can be used to distinguish every unique access point in a big WLAN?
BSSID or MAC address?
BSSID of access point is essential to every device.
You should get a WifiManager instance and then call
wifiMgr.getConnectionInfo().getBSSID()
to retrieve the BSSID as a string, it is just the MAC address of your AP, format like 0C:DE:AD:1F:00:32

I want to change MAC address of android device?

I am getting MAC address of devices using wifi interface:
WifiManager wifiMan = (WifiManager) this.getSystemService(
Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
String macAddr = wifiInf.getMacAddress();
Is there any way for retrieve mac address without wifi interface?
Also confirm me Can we able to change MAc address of android devices?
Please confirm me android framework support these things or not?
A MAC address uniquely identifies a network adapter (e.g. WiFi or Bluetooth), so you'll have to access that adapter to retrieve it's MAC address. To get the MAC address of a bluetooth adapter you can use:
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter != null) {
String mac = btAdapter.getAddress();
}
Note that this code requires the android.permission.BLUETOOTH permission and that your code to get the WiFi adapter's MAC requires the android.permission.ACCESS_WIFI_STATE permission. Also, both codes may not work when the adapter is turned off.
There is this post on MAC spoofing (returning a false MAC address) but spoofing can only be done on rooted phones. If you'll google you'll probably find more info on MAC spoofing.

MAC address is not displaying only in Nexus phone

I created a Widget which displays WiFi details. For the nexus phone only MAC address is not displaying. The code which I am using to display MAC is given below.
myWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
myWifiInfo = myWifiManager.getConnectionInfo();
mMacIp = myWifiInfo.getMacAddress();
For every other mobile it is displaying correctly.
Is the wifi off? (You can't get a MAC address of a disabled wifi).
Have you added the appropriate permissions?

Categories

Resources