/
whoisrb
executable file
·64 lines (51 loc) · 1.34 KB
/
whoisrb
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
58
59
60
61
62
63
64
#!/usr/bin/env ruby
$:.unshift(File.expand_path("../../lib", __FILE__))
require 'optparse'
require 'whois'
options = {}
OptionParser.new do |opts|
opts.banner = "Whois: an intelligent pure Ruby Whois client"
opts.define_head "Usage: ruby-whois [options] object"
opts.separator ""
opts.separator "Examples:"
opts.separator " ruby-whois ruby-lang.com"
opts.separator " ruby-whois 213.149.247.64"
opts.separator ""
opts.separator "Options:"
opts.on("-t", "--timeout [SECONDS]", Integer, "set the timeout") do |seconds|
options[:timeout] = seconds
end
opts.on("-h", "--host [HOST]", String, "connect to server HOST") do |host|
options[:host] = host
end
opts.on("--[no-]referral", "skip referral queries") do |boolean|
options[:referral] = boolean
end
opts.on_tail("--help", "show this help and exit") do
puts opts
exit
end
opts.on_tail("--version", "output version information and exit") do
puts "ruby-whois #{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
object = ARGV.shift
begin
@client = Whois::Client.new(options)
puts @client.lookup(object)
rescue Whois::Error => e
abort(e.message)
rescue Timeout::Error
abort("Request Timeout")
end