Trying to get the names of network devices with reverse DNS in Android

I can get all the IP addresses of a device on a local network with the inetaddress class. What I need to do is reverse lookup the ip address and find it as the name of the device on the network, for example: "Jimmie Macbook"

My block of code that allows you to get the entire IP address over the 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 call my method like:

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

in Log.d (TAG, I'm trying to get the device name with reverse dns. But both lines give me output as ip address (Not Device-Name as string)

Is there a chance to succeed in this?

Regards, Onder.

+6
source share
2 answers

I just do this with MACID extraction and match the first 3digits that belong to the manufacturers.

https://macvendors.com/ this site also provides api (Post / GET) for resolving the MAC address.

Instead of defining a fully qualified MAC name, you need to make a peer-to-peer Handshake connection.

+2
source

This is probably due to an incorrect router setup.

There are no important functions on the local network that depend on successful reverse DNS queries, so an incorrect configuration can be easily detected for a long time.

It is difficult to say what is wrong in your particular case, without having more detailed information about your local network, but the first thing that comes to mind is to configure the correct "DNS suffix" on the router. This can usually be found in the DHCP settings.

+1
source

All Articles