Dns.GetHostEntry .NET 2.0

G

Guest

I am trying to do a reverse DNS lookup using Dns.GetHostEntry in .NET 2.0,
but it seems to kind of crap out when the result is an answer with multiple
records. It doesnt seem to give any type of answer.

The old Dns.GetHostByAddress seems to work partially by atleast returning 1
IpHostEntry, but it has been deprecated.

Any ideas on how to retrieve the multiple records?

example:
Dns.GetHostEntry(IPAddress.Parse("207.46.130.108"));
vs.
Dns.GetHostByAddress(IPAddress.Parse("207.46.130.108"));
 
N

Nicholas Paldino [.NET/C# MVP]

RWF,

My guess is that they cleaned up the call so that if there is not a DNS
entry for this IP address (and there is not), then it throws an exception to
indicate so (a better solution would have been to return null, in my
opinion).

However, I would say it is not a bad thing to throw an exception, after
all, there is no host entry to be found to begin with!

Hope this helps.
 
W

William Stacey [MVP]

Does this blow up also?

IPHostEntry he = Dns.GetHostEntry("207.46.130.108");
if (he.Aliases.Length == 0)
{
Console.WriteLine("No host name by that address.");
return;
}
foreach(string alias in he.Aliases)
{
Console.WriteLine(alias);
}
 
G

Guest

It doesnt blow up, it just fails to return a HostName for the IPHostEntry,
but 207.46.130.108 is an IP for Microsoft.com, so there has to be something
there. When I go to dnsstuff.com and do a reverse lookup on that IP, maybe
10-15 results are returned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top