How do I get host names by using IP, MAC addresses in android

纵饮孤独 提交于 2019-12-02 09:37:35

问题


I need to get the details of all wireless devices that are connected to my wifi network. I'm getting IP, MAC addresses, somehow Vendors of device as well.

How do I get the device type? (i.e laptop, mobile, AC, Refrigerator) And host names?

InetAddress inetAddress = null;
        for (int i = 0; i < 256; i++) {
            try {
                inetAddress = InetAddress.getByName("192.168.1." + i);
                if (inetAddress.isReachable(30)) {
                    ConnectedDevice device = new ConnectedDevice();
                    device.setDeviceIPAddress(subnet + i);
                    device.setDeviceMACAddress(Utils.getMacAddressFromArpCache(inetAddress.getHostName()));

                    Log.d("Device", inetAddress.getHostName() + ", " + inetAddress.getHostAddress() + ", " + inetAddress.getCanonicalHostName() + ", " + device.getDeviceMACAddress());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

getHostName(), getHostAddress(), getCanonicalHostName() all 3 methods of inetAddress returning the ip address only. How do I get host names of connected devices on my network? What else should I do to get all the possible details of devices? Please guide me.

来源:https://stackoverflow.com/questions/36567725/how-do-i-get-host-names-by-using-ip-mac-addresses-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!