Get WiFi MAC Address summary "Go"

Source: Internet
Author: User

This article was reproduced from:

Today, the acquisition of MAC address to do some learning, the current way to get MAC address online is mainly as follows:
-Use BusyBox ifconfig
-Using cat/sys/class/net/wlan0/address
-Using wifiinfo.getmacaddress
-Using networkinterface.gethardwareaddress

In airplane mode, all basic methods are not available.

BusyBox ifconfig

Not all machines are loaded with busybox, so the compatibility with BusyBox is poor. This can be replaced with the Android Terminal Command Netcfg (the last column is the MAC address):


This method is generally more reliable by reading the MAC address information provided by the NIC driver, but as with BusyBox ifconfig or Netcfg, the returned string needs to be parsed manually.

WifiManager wifiManager=(WifiManager) getSystemService(Context.WIFI_SERVICE);WifiInfo wifiInfo=wifiManager.getConnectionInfo();String mac=wifiInfo.getMacAddress();
    • 1
    • 2
    • 3
    • 4

This method is more general, the original has been used this, but recently found that on Android 6.0 system, this method is invalid, returned to the "02:00:00:00:00:00" constant, the Internet is said to be a permission problem, but has already opened all the permissions, or return this value, It could be a bug, and maybe the problem will be fixed in the future.

Netizens prompted, found that this is not a bug, Google's blog to find the following paragraph:

Most notably, Local WiFi and Bluetooth MAC addresses is no longer available. The Getmacaddress () method of a Wifiinfo object and the Bluetoothadapter.getdefaultadapter (). GetAddress () method would both Return 02:00:00:00:00:00 from now on.


This is my current method, the principle and cat/sys/class/net/wlan0/address is identical, but this is the upper API, do not need to handle the underlying data. Tested on Android 6.0 pass.

networkInterface = NetworkInterface.getByName("wlan0");return ConvertMacAddressBytesToString(networkInterface.getHardwareAddress());

Get WiFi MAC Address summary "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.