Get Android WiFi “net.hostname” from code

2019-03-13 17:00发布

When an Android device connects to a wifi AP, it identifies itself with a name like:

android_cc1dec12345e6054

How can that string be obtained from within an Android app? Not for the purpose of changing it, just for readout.

EDIT:
This is a screenshot of my router's web interface, showing a list of all connected devices. Note the two Android devices on the list -- How can that string be read from Java code running on the device?

Router's connection list

7条回答
老娘就宠你
2楼-- · 2019-03-13 17:41

Try this:

Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class, String.class);
            String serialNumber = (String) get.invoke(c, "net.hostname", "Error");
            if (serialNumber.equals("Error")) {
                serialNumber = (String) get.invoke(c, "net.hostname", "Error");
            }
查看更多
登录 后发表回答