Create a gist now

Instantly share code, notes, and snippets.

@haqu /ava.rb
Created Feb 21, 2011

Domain availability checker
#!/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