如何获取指定主机名的DNS别名?
我试图获取有关指定主机名的 DNS 别名的信息。 我使用了:
IPHostEntry hostEntry = Dns.GetHostEntry("hostname")
不幸的是,正如 MSDN 中提到的:
此方法不会填充返回的 IPHostEntry 实例的 Aliases 属性,并且始终为空。
我计划通过以下方式获取 DNS 别名:
在注册表中获取 DNS 服务器的 ipAddresses
SYSTEM\CurrentControlSet\Services\Tcpip\Parameter
。使用 DNS WMI 提供程序获取 DNS 服务器中的 CNAME 记录。但在这种情况下,需要访问 DNS 服务器的权限。
我的计划正确吗? 有没有其他方法可以在没有 DNS 服务器许可的情况下获取 CNAME 记录?
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:
get ipAddresses of DNS server in registry
SYSTEM\CurrentControlSet\Services\Tcpip\Parameter
.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有准确回答您的问题,但正如您所指出的,别名不是由 GetHostEntry 填充的 - 方法 Dns.GetHostByName 和 Dns.Resolve 会排序填充别名。
它提供了一个你可能称之为愚蠢的不完整别名列表——据我所知,它只在按名称查找且该名称就是别名的情况下添加别名。
所以基本上如果返回的主机名与您输入的不同,那么您输入的就会被发现是别名。返回的 Alias 值确实具有完全限定名称。所以这似乎只是获取别名的完全限定名称的一种方法。
您应该注意,根据 Microsoft 的说法,这些方法都已过时,Dns 类中的大多数方法也是如此。
另请参阅 stackoverflow 帖子
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
关于 DNS Lookup 项目,值得注意的是它有一个名为 DnsProvider 的辅助类,它提供了在不使用注册表的情况下从系统获取 DNS 服务器的“正确”方法。
看
http://dnslookup.codeplex.com/wikipage?title=Usage&referringTitle=文档
了解更多信息。
Worth noting about the DNS Lookup project is it got a secondary class called DnsProvider which provides the "proper" way of getting the DNS servers from the system without using the registry.
See
http://dnslookup.codeplex.com/wikipage?title=Usage&referringTitle=Documentation
for more info on that.
Codeplex 上有一些开源 .net dns 库,您可能想查看一下。 DnDns 和 DNS 查找 都显示为活动状态并且都支持 CNAME 查找。
There are a few open source .net dns libraries on codeplex you might want to check out. DnDns and DNS Lookup both appear active and both support CNAME lookups.
您可以使用 Dns.Resolve 来获取别名。
使用 #pragma warning disable 0618 禁用对已弃用函数的警告。
如果 Ipv6Element.Enabled 属性设置为 false(默认值),则此方法有效。
https://msdn .microsoft.com/en-us/library/system.net.dns.resolve(v=vs.110).aspx
You can use Dns.Resolve to get the aliases.
Use #pragma warning disable 0618 to disable the warning on deprecated function.
This would work if Ipv6Element.Enabled property is set to false, which is the default.
https://msdn.microsoft.com/en-us/library/system.net.dns.resolve(v=vs.110).aspx