-
-
Notifications
You must be signed in to change notification settings - Fork 283
/
whoisrb
executable file
·65 lines (52 loc) · 1.35 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
65
#!/usr/bin/env ruby
# frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
require 'optparse'
require 'whois'
options = {}
OptionParser.new do |opts|
opts.banner = "Whois: an intelligent pure Ruby WHOIS client"
opts.define_head "Usage: whoisrb [options] object"
opts.separator ""
opts.separator "Examples:"
opts.separator "\t whoisrb ruby-lang.com"
opts.separator "\t whoisrb 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 "whoisrb #{Whois::VERSION}"
exit
end
begin
opts.parse!
rescue OptionParser::ParseError
puts opts
exit 1
end
if ARGV.empty?
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