Tag Archives: domain checker

Ruby – Domain Name Checker

0
Filed under ruby
Tagged as , , , , , ,

Author: slac3dork
Site: http://snippet.c0de.me
Summary:Ruby code to check domain name. This script need internet connection and create connection to http://www.who.is/. Tested on Linux.
Usage: ruby domainchecker.rb <domain_name> or ./domainchecker.rb <domain_name>
Update: This is New version, old version does not work anymore.

#!/usb/bin/ruby

#  _________      .__       .____   _______
# /   _____/ ____ |__|_____ |    |  \   _  \    ____
# \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
# /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
#/_______  /___|  /__|   __/|_______ \_____  /\___  /
#        \/     \/   |__|           \/     \//_____/
# http://snippet.c0de.me
# slac3dork@gmail.com
#
# This script was written by slac3dork
# This script is available under the GPLv3 License.
# USE COMPLETELY ON YOUR OWN RISK.
# Tested on Linux

require 'open-uri'

if ARGV.size < 1
puts '[-] Usage ./domainchecker.rb <domain_name>'
exit 1
end

puts '------------------------------------------------'
puts '[+] Domain Checker tool Version 2'
puts '[+] Author: slac3dork'
puts "-----------------------------------------------\n\n"

begin
  domain_name = ARGV[0]
  open("http://www.who.is/whois/#{domain_name}/", "User-Agent" => "Mozilla/5.0") {|page|
    page.each_line {|line|
      if (line =~ /ERROR/)
        puts '[-] ERROR! Please check your domain name'
        exit 1
      end
      if (line =~ /REGISTRY WHOIS FOR/)
        puts "[-] #{domain_name} is not available"
      end

      if (line =~ /IS AVAILABLE/)
        puts "[+] #{domain_name} is available"
      end

      if (line =~ /available_domain/)
        avail_domain = line.slice(/domain=[a-z]+[\.]{1}[a-z]{2,}/).slice(/[a-z]+[\.]{1}[a-z]{2,}/)
        puts "[+] Available Domain: #{avail_domain}"
      end
    }
  }
rescue OpenURI::HTTPError => error_msg
  puts "[-] Ups! Got bad status code: #{error_msg}. Try again"
rescue Timeout::Error
  puts '[-] oops! Timeout bro, check your internet connection'
rescue Exception => e
  puts "#{e.message}"
end

ruby,code,code,snippet