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(127.0.0.1) Ok
Dns.GetHostEntry(192.168.1.147) 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.

1 Comment

  1. Hi.

    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. 10.10.10.10 -> 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

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.