Created
February 21, 2011 15:30
-
-
Save haqu/837208 to your computer and use it in GitHub Desktop.
Domain availability checker
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
#!/usr/bin/env ruby -wKU | |
# Examples of usage: | |
# $ ava domain.com another.* unique765.{com,net} | |
# [-] domain.com | |
# [-] another.com | |
# [-] another.net | |
# [+] another.st | |
# [+] unique765.com | |
# [+] unique765.net | |
def usage | |
puts "usage: ava <domain>..." | |
exit | |
end | |
usage if ARGV.empty? | |
# supported tlds: | |
# com net org me st it | |
all_tld = %w(com net st) | |
phrases = [ | |
/no match/, | |
/no entries/, | |
/not found/, | |
/status:\s+available/ | |
] | |
domains = [] | |
ARGV.each do |d| | |
name, tld = d.split(".") | |
tld = "com" unless tld | |
if tld == "*" | |
all_tld.each do |t| domains << "#{name}.#{t}" end | |
else | |
domains << "#{name}.#{tld}" | |
end | |
end | |
domains.each do |domain| | |
ava = false | |
whois = `whois #{domain}`.downcase | |
phrases.each do |w| | |
if whois =~ w | |
ava = true | |
break | |
end | |
end | |
res = ava ? "+" : "-" | |
puts "[#{res}] #{domain}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment