Dns.GetHostEntry Method(String) 实际上是做什么的? [英] What does Dns.GetHostEntry Method(String) actually do?

查看:36
本文介绍了Dns.GetHostEntry Method(String) 实际上是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中找不到任何关于它实际作用的正确描述.

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

它是否检查 A 记录或 CNAME 记录或两者是否存在?

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

我的理解是,在 .NET 4 中,如果主机不存在,则会抛出 SocketException,我的测试证实了这一点.

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

推荐答案

Dns.GetHostEntry 建立在 Windows API 之上,不直接使用 DNS 协议.如果启用了 IPv6,它将调用 getaddrinfo.否则它会调用 gethostbyaddr.这些函数可以使用本地 %SystemRoot%System32driversetchosts 文件、DNS 甚至 NETBIOS 将主机名解析为 IP 地址.使用 DNS 将主机名解析为 IP 地址将使用 CNAME 记录来查找 A 记录.

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%System32driversetchosts 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.

您可以通过解析 www.google.com 来测试这一点,至少现在有一个指向 www.l.google.com 的 CNAME 记录.使用 Dns.GetHostEntry 将从 www.l.google.com 的 A 记录中返回 IP 地址.

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.

这篇关于Dns.GetHostEntry Method(String) 实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆