forked from weppos/whois
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arin.rb
52 lines (43 loc) · 1.18 KB
/
arin.rb
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
#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
#++
module Whois
class Server
module Adapters
#
# = Arin Adapter
#
# Provides ability to query Arin WHOIS interfaces.
#
class Arin < Base
# Executes a WHOIS query to the Arin WHOIS interface,
# resolving any intermediate referral,
# and appends the response to the client buffer.
#
# @param [String] string
# @return [void]
#
def request(string)
response = query_the_socket("n + #{string}", host)
buffer_append response, host
if options[:referral] != false && (referral = extract_referral(response))
response = query_the_socket(string, referral[:host], referral[:port])
buffer_append(response, referral[:host])
end
end
private
def extract_referral(response)
return unless response =~ /ReferralServer:\s*r?whois:\/\/([\w\.]+):?(\d+)/
{
host: $1,
port: $2 ? $2.to_i : nil
}
end
end
end
end
end