Created
April 12, 2011 15:46
-
-
Save justinxreese/915766 to your computer and use it in GitHub Desktop.
Domain availability check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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