Last Updated: February 25, 2016
·
2.62K
· weppos

Check domain availability in Ruby

The whois gem allows you to query whois information for a domain.

Install the gem via RubyGems

$ gem install whois

Use the following Ruby code to check if a domain is available.

Whois.available?(domain)

Here's an example.

def availability(domain)
  if Whois.available?(domain)
    puts "The domain #{domain} is available"
  else
    "The domain #{domain} is not available"
  end
end

puts availability("example.com")
# => The domain example.com is not available

puts availability("efdsvgerwfacdsvfbgrwefadsc.com")
# => The domain efdsvgerwfacdsvfbgrwefadsc.com is not available