Resolve IP to name when DNS not working

  • Replies:3
Keith Sheppard
  • Forum posts: 2

Jan 17, 2018, 9:01:48 PM via Website

I have an Android app that needs to access a shared folder on a Windows PC on the local network. Accessing the Windows server by name works well in some environments but in others (depending on the router in use) name to IP resolution doesn't work. Research indicates there is a generic Android problem resolving local device names in some circumstances. The problem is not specific to my app. In those environments where it fails, other apps also exhibit an inability to resolve local device names.

However, I observe that many file manager apps are able to scan the local network and deduce names for all "live" local IPs. I would like to be able to emulate this behaviour in my app - ie. scan all possible local IP addresses to see if I can get a host name for the device at each IP address.

Unfortunately, in those environments where local name resolution fails, Android interfaces like getHostName aren't any more successful, returning just the IP address passed, not the host name.

Can anyone tell me how to poll an IP address to find the host name for the device (if any) at that IP?

Please note that solutions requiring me to change my Android device's configuration are not acceptable. This app is for others to use. It would be unreasonable of me to expect my end users to start fiddling with their device settings and such adjustments would be beyond the technical capabilities of many of my target users.

Reply
James Watson
  • Forum posts: 1,584

Jan 18, 2018, 5:27:10 AM via Website

Try to call getCanonicalHostName instead of getHostName. And the calling code should be allowed to know the hostname for this IP by your WINS server.

Download size < 0.15 MB. But also accurate enough, ad-free & free.
The minimalist app available on Play Store: https://goo.gl/ws42fN
Blog: https://okblackcafe.blogspot.com Your 5-star is appreciated.

Reply
Keith Sheppard
  • Forum posts: 2

Jan 18, 2018, 5:45:15 PM via Website

James
Thanks for your interest and suggestion. Unfortunately getCanonicalHostName is no better.

Interestingly, getCanonicalHostName works fine for a public IP. It's only local IPs that fail.
For example, after executing the following code:
InetAddress diag = InetAddress.getByName("8.8.8.8");
String diagname = diag.getCanonicalHostName();
InetAddress diag2 = InetAddress.getByName("192.168.0.2");
String diagname2 = diag2.getCanonicalHostName();
diagname contains "google-public-dns....." but diagname2 just contains "192.168.0.2".

I don't think that any solution that relies on DNS is going to work. The sad fact is that there seems to be a giant hole in Android's ability to resolve names of local devices via DNS. However, it clearly is possible to associate names with IP addresses. Using the same tablet in the same environment, if I run a commercial network-aware File Manager app and ask it to scan the local network, it correctly lists a server called HomeStore with the IP address 192.168.0.2.

The File Manager app takes a fair while to scan the network so I suspect it is entering into some sort of conversation with every live IP address from 192.168.0.0 to 192.168.0.255(?) asking each server directly what its device name is. That's the behaviour I need to emulate. Is there some sort of message exchange that would allow me to interact, experimentally, with an IP address and determine the name of the server (if any) sitting on that IP?

Keith

Reply
GLekter
  • Forum posts: 1

Feb 24, 2021, 8:33:44 AM via Website

This is a very familiar problem,I also needed to transfer small files between the computer and the phone. I was helped by the guides found on the Internet.

Reply