Sunday, February 19, 2012

Ruby Whois Script - whois.rb

Description: My old script. Client for the whois directory service.
#!/usr/bin/env ruby

# www.railsmine.net

require 'open-uri'

if ARGV.size < 1
puts '[-] Usage: ruby whois.rb [domain_name]'
exit 1
end

puts '-----------------------------------------------'
puts '[+] Whois tool - whois.rb'
puts "-----------------------------------------------\n\n"

begin
 domain_name = ARGV[0]
 open("http://reports.internic.net/cgi/whois?whois_nic=#{domain_name}&type=domain") {|page|
     page.each_line {|line|
      if (line =~ /Domain Name:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Registrar:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Name Server:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Whois Server:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Referral URL:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Status:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Updated Date:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Creation Date:/)
       puts "[+]#{line}"
                    end

      if (line =~ /Expiration Date:/)
       puts "[+]#{line}"
                    end
  }
    }
rescue OpenURI::HTTPError => error_msg
        puts "[-] Oops! Bad status code: #{error_msg}. Please try again."
rescue Timeout::Error
        puts '[-] 0ops! Timeout, Check your internet connection.'
end

5 comments:

  1. You are well aware of such gems as https://github.com/weppos/whois, aren't you? Have a look on their usefull gem public_suffix_service, too?

    ReplyDelete
    Replies
    1. yes I know Whois gem. I just want to re-share my old script.

      Delete
  2. Wow that needs refactoring! Copy/Paste horror in Ruby is like eating raw chicken because you're too lazy too grill it.

    ReplyDelete
  3. I have made a php whois script http://mkj.co.in/?p=52

    ReplyDelete
  4. Thanks for your useful information. There are lot of ways available to find whois information. I have checked my whois histroy from this site Whoisxy.com

    ReplyDelete

© Railsmine