Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get DNS aliases of specified host name?

Tags:

c#

.net

dns

wmi

I am tying to get information about DNS aliases of specified host name. I used :

IPHostEntry hostEntry = Dns.GetHostEntry("hostname")

Unfortunately as mentioned in MSDN:

The Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

I plan to get DNS aliases such way:

  1. get ipAddresses of DNS server in registry SYSTEM\CurrentControlSet\Services\Tcpip\Parameter.

  2. use DNS WMI provider to get CNAME records in the DNS server. But in this case permissions for access to the DNS server are requiered.

Is my plan correct? Is there another way to get CNAME records without permission to DNS server?

like image 389
shtriha Avatar asked Nov 14 '22 02:11

shtriha


1 Answers

Not answering your question exactly, but as you noted that the aliases are not populated by GetHostEntry - methods Dns.GetHostByName and Dns.Resolve do sort-of populate the Aliases.

It gives what you might call a stupidly incomplete list of aliases -- as far as I can tell, it only adds the alias if the look-up was by name, and that name was the alias.

So basically if the returned host name is different from what you input, then what you input is found to be the alias. The returned Alias value does have the fully qualified name. So this really just seems to be a way to get the fully qualified name of an alias.

You should note that per Microsoft, these methods are both obsolete, as are most of the methods in class Dns.

See also stackoverflow posts

  • .NET GetHostByAddress aliases only showing up 8 entries
  • C# resolving DNS aliases for a host
like image 129
Abacus Avatar answered Dec 13 '22 10:12

Abacus