Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get network device names with reverse dns in Android

I can able to fetch all device ip addresses in Local Area Network with inetaddress class. What I need to do is reverse lookup ip-address and find as device name in network like : "Jimmie's Macbook"

My Code block which able to fetch all IP address over Local Network Range:

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

And i am calling my method as;

ArrayList<String> subnetList = scanSubNet("192.168.1.");ArrayList<String> subnetList = scanSubNet("192.168.1.");

in Log.d(TAG, i am trying to get device name with reverse dns. But both of line gives me output as ip-address ( Not Device-Name as string)

Is there any chance to succeed it ?

Regards, Onder.

like image 367
Onder OZCAN Avatar asked Sep 21 '16 08:09

Onder OZCAN


1 Answers

I just do it with fetching MACID and match first 3digits which belongs manufacturers.

https://macvendors.com/ this website also provide api (Post/GET) to resolve MAC Address.

Instead of resolve fullname of MAC, you need to do Handshake peer to peer.

like image 121
Onder OZCAN Avatar answered Oct 13 '22 10:10

Onder OZCAN