Dns.GetHostEntry 错误情况及解决方法 [英] Dns.GetHostEntry error conditions and resolution methods

查看:21
本文介绍了Dns.GetHostEntry 错误情况及解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Dns.GetHostEntry 的非常具体的问题:

I have a very specific problem concerning Dns.GetHostEntry:

服务使用 Dns.GetHostEntry 来检索主机的所有 IP 地址,使用主机的名称.这一直很好用.对于特定客户,当查询特定主机时,Dns.GetHostEntry 会抛出没有已知的此类主机"错误.只有在尝试解析与安装服务的机器位于不同域的主机时,才会出现此问题.该服务已经工作了很长一段时间,但最近停止工作,抛出没有已知这样的主机"错误(遗憾的是,没有可用的堆栈跟踪).Nslookup 可以工作,但没有问题.有问题的服务是用 VB.NET 编写的,针对 .NET Framework 2.0.

A service uses Dns.GetHostEntry to retrieve all IP Adresses of a host, using the name of of the host. This has always worked fine. At a specific customer, Dns.GetHostEntry throws the "no such host is known" error when querying specific hosts. The problem only occurs when trying to resolve hosts that are on a different domain than the machine the service is installed on. The service has worked for quite some time, but recently is stopped working, throwing the "no such host is known" error (sadly, no stack trace is available). Nslookup works though, no problems there. The service in question is written in VB.NET, targetting the .NET Framwork 2.0.

.NET 3.0 的 MSDN 条目中的注释 (http://msdn.microsoft.com/en-us/library/ms143998(v=VS.85).aspx 表明主机的反向 DNS 条目可能有问题,但我即使删除了所有反向查找区域,也无法在测试网络上重现该问题(其他 .NET 版本有更多评论,所有版本都存在类似问题). 即使故意添加错误的 PTR 记录也不会使问题出现在我的测试机上.

The comments in the MSDN entry for .NET 3.0 (http://msdn.microsoft.com/en-us/library/ms143998(v=VS.85).aspx indictate that there may be a problem with the reverse DNS entries for the hosts, but I was not able to reproduce the problem on a test network, even with all reverse lookup zones deleted (there are more comments for other .NET Versions, all having similiar problems). Even deliberatly addind a wrong PTR record does not make the problem occur on my test machine.

导致错误出现的唯一原因是断开网络适配器的连接,从而使 DNS 服务器不可用,即使由于缓存,正向解析仍然有效.

The only thing that made the error come up was disconnecting the network adapter, and thereby making the DNS Server unavailable, even though the forward resolving still worked due to caching.

所以,我的问题是:

  1. GetHostEntry 在什么情况下会抛出此特定错误?
  2. 它使用哪些解析方法?如果我没记错的话,它使用非托管 WinSock 函数 getnameinfo (http://msdn.microsoft.com/en-us/library/ms738532(v=vs.85).aspx),: "名称解析可以通过域名系统 (DNS),本地主机文件,或通过其他命名机制".
  3. 知道为什么这会突然在另一个域中的机器上失败(但对于同一域中的机器却没有)?
  1. Under which conditions does GetHostEntry throw this specific error?
  2. Which resolution methods does it use? If I'm not mistaken it uses the unmanaged WinSock function getnameinfo (http://msdn.microsoft.com/en-us/library/ms738532(v=vs.85).aspx),: "Name resolution can be by the Domain Name System (DNS), a local hosts file, or by other naming mechanisms".
  3. Any ideas why this suddenly fails for machines on the other domain (but not for machines on the same domain)?

谢谢和最好的问候,cun83

Thanks and best regards, cun83

推荐答案

我个人总是使用 Dns.GetHostAddresses.它总是给我一个可靠的结果.

I personally always use Dns.GetHostAddresses. It always gives me a reliable result.

关于为什么 Dns.GetHostEntry给你指定的错误,我认为这是由于 DnsGetHostEntry 将尝试在返回 IP 地址之前进行反向 DNS 查找.如果反向 DNS 查找失败,它会给你没有这样的主机是已知的".

Regarding to why Dns.GetHostEntry gives you the specified error, I think it's due to the fact that DnsGetHostEntry will attempt to do a reverse DNS lookup before returning you the IP address. If reverse DNS lookup fails, it will give you "no such host is known".

据我所知,Dns.GetHostAddresses 只返回 IP 地址.

As far as I know, Dns.GetHostAddresses just returns the IP address.

这篇关于Dns.GetHostEntry 错误情况及解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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