Skip to content

Instantly share code, notes, and snippets.

@joaumg
Created August 14, 2017 16:00
Show Gist options
  • Save joaumg/1e04ae325bacc9242497e656a722d36a to your computer and use it in GitHub Desktop.
Save joaumg/1e04ae325bacc9242497e656a722d36a to your computer and use it in GitHub Desktop.
Use the american dictionary to search for available domains.
#!/usr/bin/ruby
require 'whois'
require 'whois-parser'
require 'logger'
#
class WhoisDiscovery
def initialize
$stdout.sync = true
@logger = Logger.new($stdout)
File.open('/usr/share/dict/american-english', 'r').each_line do |word|
word = word.strip
next if word.include? "'"
whois("#{word}.com")
end
end
def whois(domain)
@logger.info "> whois(#{domain})"
parser = Whois::Client.new(timeout: 10).lookup(domain).parser
available = parser.available?
expires_on = parser.expires_on
@logger.info "< whois(#{domain}, #{available}, #{expires_on})"
rescue Timeout::Error, Whois::ConnectionError, Whois::ParserError
@logger.debug "whois.lookup(#{domain}) failed"
end
end
WhoisDiscovery.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment