GetHostEntry是很慢 [英] GetHostEntry is very slow

查看:1388
本文介绍了GetHostEntry是很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,而我试图获取反向DNS条目表单上显示的IP地址列表。

I have a WinForms app, and I'm trying to get reverse DNS entries for a list of IPs displayed on the form.

我碰到的主要问题是System.Net.Dns.GetHostEntry是可笑缓慢,特别是当被发现的反向DNS条目。随着直DNS,这应该是快,因为DNS服务器将返回NXDOMAIN。在内部,它调用 ws2_32.dll中则getnameinfo(),其中规定名称解析可以通过域名系统(DNS),本地hosts文件,或者通过其他的命名机制 - 所以我假设它的那些其他的命名机制是造成它是如此缓慢,但没有人知道是什么这些机制是什么?

The main issue I've run into is System.Net.Dns.GetHostEntry is ridiculously slow, particularly when no reverse DNS entry is found. With straight DNS, this should be fast, since the DNS server will return NXDOMAIN. Internally, it's calling ws2_32.dll getnameinfo(), which states "Name resolution can be by the Domain Name System (DNS), a local hosts file, or by other naming mechanisms" - so I'm assuming it's those "other naming mechanisms" that's causing it to be so slow, but does anyone know what those mechanisms are?

一般来说,这是服用5秒每个IP,除非它找到一个反向项,然后它几乎即时的。我部分的工作该使用线程左右,但因为我做了大名单,我只能同时运行这么多线程,它仍然需要一段时间才能通过他们所有。

Generally this is taking 5 seconds per IP, unless it finds a reverse entry, and then it's almost immediate. I've partly worked around this using threads, but since I am doing a large list and I can only run so many threads at once, it still takes a while to get through them all.

有没有更好的方法来找到反向DNS条目将是更快?

Is there a better way to find reverse DNS entries that is going to be faster?

推荐答案

不幸的是,有没有办法(其中我知道),以改变这种超时在Windows API中,在客户端。你能做的最好的就是修改注册表来改变超时的长度DNS查询。请参见见此TechNet文章细节。据我所知,试图1,2,和放大器; 3,当你做到这一点,所以5秒延时运行。

Unfortunately, there is no way (of which I am aware) to change this timeout in the Windows API, on the client side. The best you can do is edit the registry to alter the length of the timeouts in DNS queries. See this technet article for details. To my knowledge, attempts 1, 2, & 3 are run when you do this, hence the 5 second delay.

唯一的其他选择是使用某种形式的背景处理,如本<一个href="http://www.chapleau.info/cs/blogs/fchapleau/archive/2008/09/09/reverse-dns-lookup-with-timeout-in-c.aspx">asynchronous反向DNS查找版本。这是将要使用的线程,虽然如此,你最终会运行到超时(它会更好,因为它会在许多等待的线程,但还不够完善)。就个人而言,如果你要处理一个庞大的数字,我会混合使用这两种方法 - 做一个反向查找ansyncrhonously和修改注册表,使的超时时间

The only other option is to use some form of background processing, such as this asynchronous version of reverse DNS lookups. This is going to use threading, though, so you'll eventually run into the timeouts (it'll be better, since it'll be across many waiting threads, but still not perfect). Personally, if you're going to process a huge number, I'd mix both approaches - do a reverse lookup ansyncrhonously AND modify the registry to make the timeout shorter.


意见后编辑:

如果你看一下在 getnameinfo将的标志,有一个标志参数。我相信你可以P / Invoke到这一点,并设置标志 NI_NAMEREQD | NI_NUMERICHOST 来得到你所追求的行为。 (第一次说,立刻报错了,如果没有DNS条目,这有助于超时 - 第二个说,这样做的反向查找)

If you look at the flags on getnameinfo, there is a flags parameter. I believe you can P/Invoke into this and set the flags NI_NAMEREQD | NI_NUMERICHOST to get the behavior you are after. (The first says to error out immediately if there is no DNS entry, which helps the timeout - the second says to do the reverse lookup.)

这篇关于GetHostEntry是很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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