C # Dns.GetHostEntry doesn't return names of mobile devices connected to WiFi

I have a Windows Form Application in C # and I am trying to get the hostname of all the clients I have in the list. Below is a sample code from ra00l from this link: GetHostEntry is very slow (I have similar code but this one is clean)

private delegate IPHostEntry GetHostEntryHandler(string ip);
public string GetReverseDNS(string ip, int timeout) 
{
     try
     {
          GetHostEntryHandler callback = new GetHostEntryHandler(Dns.GetHostEntry);
          IAsyncResult result = callback.BeginInvoke(ip,null,null);
          if (result.AsyncWaitHandle.WaitOne(timeout, false))
          {
               return callback.EndInvoke(result).HostName;
          }
          else 
          {
               return ip;
          }
     } 
     catch(Exception)
     {
          return ip;
     }
}

      

When it sets the IP address of a Windows machine on the network, it shows the correct hostname, given that you are entering a reasonable timeout. After the tests I did, I didn't get an answer for Android and Apple hostnames. For example, the picture below is a list of DHCP clients for a router that I have. It shows devices for Android, Apple and laptops. I am using a "Nathu-Laptop" which gives me the IP address "192.168.1.106".

enter image description here

If I enter '192.168.1.105' into a C # function, the result is "Nandwani-PC", but if I enter "192.168.1.103", "192.168.1.104", "192.168.1.101", "192.168.1.101", "192.168.1.100" ', I am not getting any hostname.

I also tried using nbtstat, but it only gets laptops on the network.

When I try to do this on my iPod, I guarantee there is network activity. This is necessary to maintain communication as it disconnects from the network when it is in standby mode.

EDIT:

So I found out that DNS.GetHostEntry calls getaddrinfo if IPv6 is enabled, otherwise call gethostbyaddr and these functions can access data from \System32\drivers\etc\hosts

or possibly from NETBIOS. Is it that NETBIOS is the heir to the right? but what about mobile devices?

+3


source to share


1 answer


About NetBIOS:

To answer your specific questions about NetBIOS and network name resolution, I'll provide more details. If you don't have a DNS server running on your network, name resolution will only rely on NetBIOS resolution. Standard and implemented in several operating systems. However, this is not very fast.

Even if we are old, we are not obsolete from the past and obsolete

You can check Microsoft Support for how names are resolved in Windows and NetBIOS is the latter.



However, NetBios name resolution is not always fully functional (for example, this bug on Android, which was fixed in 2014 ) on all mobile platforms (depends on the Android version, for example). If you want to improve performance, I suggest you set up a DNS server on your network.

Have you tried ping -a <IP address>

or nslookup <IP address>

checked if the results meet your expectations?

If your problem still persists, you can investigate the .Net implementation using the links above. You can also check out a more modern version of the .Net DNS implementation here

+3


source







All Articles