Using Dns class

  • Thread starter Thread starter Johno
  • Start date Start date
J

Johno

I'm using the Dns class to query host names to check that
they actually exist on our network and to determine the
aliases for each host name. However, I've noticed that the
IPHostEntry instance returned by Dns.GetHostByName doesn't
return the host name's aliases in the IPHostEntry.Aliases
list. But if I pass a host alias to GetHostByName it
returns the alias in IPHostEntry.Aliases and the true host
name in IPHostEntry.Hostname.

It appears that the IPHostEntry.Aliases does not work in
the way suggested by the SDK docs, but can anyone tell me
how I can get a list of DNS aliases for a known DNS host
entry?

Thanks

John
 
Johno said:
I'm using the Dns class to query host names to check that
they actually exist on our network and to determine the
aliases for each host name. However, I've noticed that the
IPHostEntry instance returned by Dns.GetHostByName doesn't
return the host name's aliases in the IPHostEntry.Aliases
list. But if I pass a host alias to GetHostByName it
returns the alias in IPHostEntry.Aliases and the true host
name in IPHostEntry.Hostname.

It appears that the IPHostEntry.Aliases does not work in
the way suggested by the SDK docs, but can anyone tell me
how I can get a list of DNS aliases for a known DNS host
entry?
John -

This is not a bug in GetHostByName() or IPHostEntry - it is the
way DNS works. You should notice that using the nslookup command
produces the same results. It is impossible to list all of the alias
records that might be associated with a host name record without
querying the entire DNS tree (its possible for an alias record to
point to a host in another domain). The GetHostByName() method will
walk the chain of aliases to the root host name if it is supplied an
alias name. That is what the IPHostEntry.Aliases property is used for.

As an example, try www.microsoft.com. If you look it up, it shows
that it is an alias, pointing to www.microsoft.com.edgesuite.net,
which is another alias pointing to the host a562.cd.akamai.net. Now if
you look up www.microsoft.com.edgesuite.net, it only shows that it is
an alias to the a562.cd.akamai.net host - it doesn't know about the
www.microsoft.com alias, as it is farther up the alias chain. The
nslookup can only follow the alias chain down to the actual host name.

Some DNS utilities (such as the Unix 'dig' command), can query an
entire domain looking for all of the alias (CNAME) and host name (A)
DNS records. You may have to model your app after one of those
programs to get the information you are interested in. Hope this helps
shed some light on your problem. Good luck with your network app.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 
Rich,

Thanks for the reply. I did suspect that this was the way
DNS works because, like you say, NSLOOKUP behaves in the
same way as GetHostByName()/IPHostEntry.

Regards

John
 
Back
Top