Why would GetHostByAddress fail only for Windows 7 clients?

Go To StackoverFlow.com


In a web application using the System.Net.GetHostByAddress method, we're having issues with the method returning the wrong host name.

The problem is that given an IP address, it is consistently returning an incorrect host name, for Windows 7 clients only. Systems running Windows XP return their host name normally.

The code we use looks like this:

host = System.Net.Dns.GetHostByAddress(GetIPv4Address)
strComputerName = host.HostName

GetIPv4Address is the address accessing the web app. However, we've also tried directly hard coding IP addresses with the same results:

host = System.Net.Dns.GetHostByAddress("")
strComputerName = host.HostName

The final wrinkle is that for any given IP address GetHostByAddress returns the same (incorrect) host name most of the time. However, every once in a while it will throw a SocketException: No such host is known.


  • We switched to GetHostByAddress from GetHostEntry on the advice of comments on the API documentation.

  • GetHostEntry also returns incorrect results.

  • Further investigation has revealed that nslookup returns results similar to what we're getting from GetHost*. So it may not be a .NET issue. We're contacting our network admins to see if they can work it out.

2012-04-04 17:42
by AaronSieb


GetHostByAddress is deprecated. Here's how I'm doing it:

string ComputerName;
    ComputerName = System.Net.Dns.GetHostEntry(IPAddress).HostName;
catch (Exception e)
    ComputerName = "Unknown";

This works for Windows 7 clients for me. I haven't tried GetHostByAddress, so ymmv.

2012-04-04 23:58
by Mike B
We'd switched to GetHostByAddress on the advice of commentors in the API documentation. GetHostEntry also returns odd results. However, further investigation has shown that nslookup also returns odd results, so it's likely not a .NET error.. - AaronSieb 2012-04-05 16:03