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.
source share