Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 58 lines (46 sloc) 1.182 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/env ruby -wKU

$:.unshift(File.dirname(__FILE__) + "/../lib")

require 'optparse'
require 'ostruct'
require 'whois'


options = OpenStruct.new
OptionParser.new do |opts|
  opts.banner = "Whois: an intelligent pure Ruby Whois client"
  opts.define_head "Usage: whois [options] object"
  opts.separator ""
  opts.separator "Examples:"
  opts.separator " whois ruby-lang.com"
  opts.separator " whois 213.149.247.64"
  opts.separator ""
  opts.separator "Options:"

  opts.on("-t", "--timeout [SECONDS]", Integer, "Specify the timeout value") do |seconds|
    options.timeout = seconds
  end

  opts.on_tail("--help", "Show this message") do
    puts opts
    exit
  end

  opts.on_tail("-v", "--version", "Show version") do
    puts "#{Whois::NAME} #{Whois::VERSION}"
    exit
  end

  begin
    opts.parse!
  rescue OptionParser::ParseError
    puts opts
    exit 1
  end

  if ARGV.size.zero?
    puts opts
    exit 1
  end
end

qstring = ARGV.shift

begin
  @client = Whois::Client.new(:timeout => options.timeout)
  puts @client.query(qstring)
rescue Whois::Error => e
  abort(e.message)
rescue Timeout::Error => e
  abort("Request Timeout")
end
Something went wrong with that request. Please try again.