What does Dns.GetHostEntry Method(String) actually do?

纵然是瞬间 提交于 2019-12-21 12:01:34

问题


I can't find any proper description in the documentation for what this actually does.

Does it check for the existence of A records or CNAME records or both?

My understanding is that in .NET 4, this throws a SocketException if the host does not exist, and this is confirmed by my testing.


回答1:


This is the list of addresses returned by

var ips = System.Net.Dns.GetHostEntry("microsoft.com").AddressList;
foreach (var ip in ips)
    Console.WriteLine(ip);

// output
64.4.11.37
65.55.58.201

And these are the A records pulled from network-tools.com, DNS query.

Answer records
microsoft.com       A   64.4.11.37  
microsoft.com       A   65.55.58.201

So I'd say it does pull A records.




回答2:


Dns.GetHostEntry is built on top of the Windows API and does not use the DNS protocol directly. If IPv6 is enabled it will call getaddrinfo. Otherwise it will call gethostbyaddr. These functions may use the local %SystemRoot%\System32\drivers\etc\hosts file, DNS or even NETBIOS to resolve a host name to an IP address. Resolving a host name to an IP address using DNS will use CNAME records to find the A record.

You can test this by resolving www.google.com that at least right now has a CNAME record that points to www.l.google.com. Using Dns.GetHostEntry will return the IP addresses from the A records for www.l.google.com.



来源:https://stackoverflow.com/questions/10910622/what-does-dns-gethostentry-methodstring-actually-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!