尝试在Android中使用反向DNS获取网络设备名称

Ond*_*CAN 6 dns android inetaddress android-networking

我可以使用inetaddress类获取局域网中的所有设备IP地址.我需要做的是反向查找ip-address并在网络中找到设备名称,如:"Jimmie的Macbook"

我的代码块能够通过本地网络范围获取所有IP地址:

        private ArrayList<String> scanSubNet(String subnet) {
            ArrayList<String> hosts = new ArrayList<>();
            InetAddress inetAddress;

            for (int i = 1; i <= 255; i++) {
                try {
                    inetAddress = InetAddress.getByName(subnet + String.valueOf(i));

                    if (inetAddress.isReachable(1000)) {
                        hosts.add(inetAddress.getHostName());
                        Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getHostAddress());
                        Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getCanonicalHostName());
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            return hosts;
        }
Run Code Online (Sandbox Code Playgroud)

我称之为我的方法;

ArrayList<String> subnetList = scanSubNet("192.168.1.");ArrayList<String> subnetList = scanSubNet("192.168.1.");
Run Code Online (Sandbox Code Playgroud)

在Log.d(TAG,我试图用反向dns获取设备名称.但两行都给我输出为ip-address(非设备名称为字符串)

有没有机会成功呢?

此致,Onder.

Ond*_*CAN 2

我只是通过获取 MACID 并匹配属于制造商的前 3 位数字来完成此操作。

https://macvendors.com/该网站还提供 api (Post/GET) 来解析 MAC 地址。

您需要进行点对点握手,而不是解析 MAC 的全名。