C# and Dns.GetHostEntry

I am currently building a new FTP automation for Navision.

During this I discovered that Dns.GetHostEntry is not always stable.

So I did some testing. Here are some of the results:

Dns.GetHostEntry(localhost) Ok
Dns.GetHostEntry( Ok
Dns.GetHostEntry( No Such Host is Known

The funny side is that its all to the same ftp server.

It seams, that Dns.GetHostEntry often throws the exception (No Such Host is Known).

So, what to do? Well I have chosen to use the command Dns.GetHostAddresses instead of Dns.GetHostEntry.

The difference between GetHostEntry and GetHostAddresses is that GetHostEntry will attempt a DNS reverse resolve before giving you the IP address back, where as GetHostAddress just returns the IP address.

You can leave a response, or trackback from your own site.

One Response to “C# and Dns.GetHostEntry”

  1. Logi says:


    I just stumbled on this error in a small utility im writing and I think I know why this is failing. If you look up an IP address the function starts a reverse DNS lookup of the address and then does a normar DNS lookup on the result it got from the reverse lookup. If it gets an response from the reverse lookup (i.e. -> computer.example.com) it does a forward lookup for “computer.example.com”. If for some reasone the forward lookup is not registerd in the the DNS you get a “No such host is known” error. To test this, just do a “nslookup” on the command line for the IP address and the do a lookup for the answare you get from the query.

Leave a Reply

7 − = two