DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Domains Availability Checker

04.14.2007
| 5402 views |
  • submit to reddit
        /*
This script uses whois program to check domain for "No match" record.
Example of usage:
$ ./ava.rb ruby{,-}snippets rubyzone.*  
- rubysnippets.com
+ ruby-snippets.com
- rubyzone.com
- rubyzone.net
- rubyzone.org
*/

#!/usr/bin/env ruby -w

if ARGV.empty?
  puts <<-T
domains availability checker by haqu
usage: ./ava.rb url[.tld|.*] ...
  T
  exit
end

domains = []

ARGV.each do |d|
  if d.include?(".*")
    dset = d.gsub(/\*/,"")
    domains << [ "#{dset}com", "#{dset}net", "#{dset}org" ]
  else
    domains << d
  end
end
domains.flatten!

domains.each do |d|
  res, domain = "-", d
  unless domain.include?(".")
    domain += ".com"
  end
  whois = `whois #{domain}`
  res = "+" if whois.include?( "No match" )
  puts "#{res} #{domain}"
end