ECONNRESET(Whois :: ConnectionError) - 尝试在Ruby中查询Whois时出错

时间:2011-04-28 21:17:55

标签: ruby whois whois-ruby

我正在Ruby中编写一个简单的程序来检查是否采用了域列表。基本上它循环遍历列表,并使用以下函数进行检查。

require 'rubygems'
require 'whois'

def check_domain(domain)
  c = Whois::Client.new
  c.query("google.com").available?
end

该程序不断出错(即使我在google.com上进行硬编码),并打印下面的消息。鉴于该计划有多简单,我已经没有想法 - 任何建议?

/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.rb:165:in `query_the_socket': Errno::ECONNRESET: Connection reset by peer (Whois::ConnectionError)
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/verisign.rb:41:in `request'
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.rb:113:in `query'
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.rb:150:in `buffer_start'
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.rb:112:in `query'
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/client.rb:90:in `query'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
from /Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/client.rb:87:in `query'
from checker.rb:7:in `check_domain'
from checker.rb:14
from checker.rb:11:in `each'
from checker.rb:11

3 个答案:

答案 0 :(得分:5)

这个问题有两种可能的解释:

  1. 您位于防火墙/代理后面且客户端无法访问服务器
  2. (更现实)您的请求受到限制。某些.COM服务器(如GoDaddy)用于重置连接,以防止多个查询。见this ticket。您可以通过限制对同一服务器的请求数来解决此问题。

答案 1 :(得分:2)

尝试使用timeout参数:

irb(main):002:0> c = Whois::Client.new(:timeout => 100) # 100 seconds
irb(main):003:0> c.query("google.com").available?
=> true

答案 2 :(得分:1)

之前有效吗? 您向whois服务器发出的请求太多了。慢下来。

之前没有工作? 你无法访问whois服务器