Skip to content

Instantly share code, notes, and snippets.

@justinxreese
Created April 12, 2011 15:46
Show Gist options
  • Save justinxreese/915766 to your computer and use it in GitHub Desktop.
Save justinxreese/915766 to your computer and use it in GitHub Desktop.
Domain availability check
# Check to see if a domain is available (unregistered)
def available?(domain_name)
# Use Net::DNS library via ruby gems
require 'rubygems'
require 'net/dns/resolver'
res = Net::DNS::Resolver.new
# Use Google public DNS for speed
res.nameservers = ["8.8.8.8","8.8.4.4"]
res.udp_timeout=(60)
packet = res.search(domain_name, Net::DNS::NS)
# Check for domains packets with Answers
# This means a domain returned a DNS record (registered)
if(packet.header.anCount > 0)
return false
else
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment