How to get DNS aliases of a specified hostname?

I am contacting to obtain DNS alias information for the specified host name. I used:

IPHostEntry hostEntry = Dns.GetHostEntry("hostname") 

Unfortunately, as mentioned on MSDN:

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

I plan on getting DNS aliases this way:

  • get ipAddresses DNS server in the registry SYSTEM\CurrentControlSet\Services\Tcpip\Parameter .

  • Use the DNS WMI provider to retrieve CNAME records on the DNS server. But in this case, permissions are required to access the DNS server.

Is my plan right? Is there any other way to get CNAME records without permission on the DNS server?

+4
source share
4 answers

It is worth noting that the DNS Lookup project has received an additional DnsProvider class, which provides the "correct" way to get DNS servers from the system without using the registry.

See http://dnslookup.codeplex.com/wikipage?title=Usage&referringTitle=Documentation for more information about this.

0
source

There are several open source .ple dns libraries on codeplex that you might want to check out. DnDns and DNS Lookup are displayed as active as well as CNAME Search support.

0
source

Not answering your question exactly, but since you noted that the aliases are empty GetHostEntry - the Dns.GetHostByName and Dns.Resolve methods do sort sorting of the aliases .

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

So basically, if the return host name is different from what you enter, then what you enter is an alias. The returned alias value has a fully qualified name. So this is really just a way to get the full alias name.

It should be noted that for Microsoft these methods are deprecated, like most methods in the Dns class.

See also stackoverflow posts

0
source

You can use Dns.Resolve to get aliases. Use #pragma warning disable 0618 to disable the warning for an obsolete function. This will work if the Ipv6Element.Enabled property is set to false, which is the default value.

https://msdn.microsoft.com/en-us/library/system.net.dns.resolve(v=vs.110).aspx

0
source

Source: https://habr.com/ru/post/1341870/


All Articles