5

I'm writing a simple program in Ruby to check if a list of domains is taken. Basically it cycles through a list, and uses the following function to check.

require 'rubygems'
require 'whois'

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

The program keeps erroring out (even when I hardcode in google.com), and prints the message below. Given how simple the program is, I've run out of ideas - any suggestions?

/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
spencer.sm
  • 19,173
  • 10
  • 77
  • 88
raven001
  • 97
  • 1
  • 5

3 Answers3

5

The are two possible explanations to this issue:

  1. you are behind a firewall/proxy and the client can't reach the server
  2. (more realistic) your request is being throttled. Some .COM servers, such as GoDaddy, are used to reset the connection as a way to protect against multiple queries. See this ticket. You can solve this problem by limiting the number of requests to the same server.
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • Simone, firstly great reply. I've run into this issue myself recently and this helps a lot. If I am only interested in domain availability as opposed to full whois info, is there a better way I should be checking it than with the whois gem? [Perhaps like this](http://stackoverflow.com/a/1780698/574190)? – David Tuite Mar 21 '12 at 01:48
  • @duckyfuzz you should open a new question. I posted an answer in the question you referenced where I explain why DNS check is not affordable. The only way to determine a domain availability is running a WHOIS query using a library or a web service. Have a look at [RoboWhois](http://www.robowhois.com/), it's powered by the whois gem but it offers an HTTP API. – Simone Carletti Mar 21 '12 at 08:45
  • Whoops yeah I didn't read past the first answer. I see your reply now. My rate limiting appears to be getting pretty severe now. I've gotten `Errno::ECONNRESET` on about 82/730 availability checks with the Whois gem over a 2 day period. Does this sound extreme or normal? – David Tuite Mar 21 '12 at 15:21
  • Simone, I just emailed you on your personal email (the one you have on your personal site) with some follow up questions about RoboWhois. Thanks for your help so far. – David Tuite Mar 21 '12 at 15:41
  • 1
    You're welcome. It looks like the origin of your problems is because you are sending out queries from Heroku and... chances are you are not the only Heroku user performing WHOIS requests. ;) – Simone Carletti Mar 21 '12 at 16:02
2

Try to use the timeout param:

irb(main):002:0> c = Whois::Client.new(:timeout => 100) # 100 seconds
irb(main):003:0> c.query("google.com").available?
=> true
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
1

Was it working before? You are making too many requests to whois server. Slow down.

Was not working before? You can't reach whois server

Lukas Liesis
  • 24,652
  • 10
  • 111
  • 109