whois 5.0.1 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +6 -2
- data/.github/dependabot.yml +19 -0
- data/.github/workflows/codeql-analysis.yml +64 -0
- data/.github/workflows/release.yml +16 -0
- data/.github/workflows/tests.yml +30 -0
- data/.rubocop.yml +27 -0
- data/.rubocop_opinionated.yml +135 -0
- data/.rubocop_todo.yml +166 -0
- data/.simplecov +2 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +86 -54
- data/CONTRIBUTING.md +12 -12
- data/Gemfile +6 -1
- data/LICENSE.txt +1 -1
- data/README.md +22 -22
- data/Rakefile +12 -17
- data/bin/console +1 -0
- data/bin/whoisrb +4 -3
- data/data/ipv4.json +1 -3
- data/data/tld.json +10 -103
- data/lib/whois/client.rb +4 -2
- data/lib/whois/errors.rb +4 -2
- data/lib/whois/record/part.rb +5 -4
- data/lib/whois/record.rb +4 -2
- data/lib/whois/server/adapters/afilias.rb +4 -1
- data/lib/whois/server/adapters/arin.rb +7 -4
- data/lib/whois/server/adapters/arpa.rb +20 -19
- data/lib/whois/server/adapters/base.rb +26 -40
- data/lib/whois/server/adapters/formatted.rb +4 -2
- data/lib/whois/server/adapters/none.rb +3 -1
- data/lib/whois/server/adapters/not_implemented.rb +3 -1
- data/lib/whois/server/adapters/standard.rb +4 -2
- data/lib/whois/server/adapters/verisign.rb +4 -1
- data/lib/whois/server/adapters/web.rb +3 -1
- data/lib/whois/server/socket_handler.rb +8 -6
- data/lib/whois/server.rb +41 -47
- data/lib/whois/version.rb +4 -2
- data/lib/whois.rb +15 -13
- data/spec/integration/whois_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -4
- data/spec/support/helpers/connectivity_helper.rb +3 -3
- data/spec/support/helpers/spec_helper.rb +2 -0
- data/spec/whois/client_spec.rb +8 -9
- data/spec/whois/record/part_spec.rb +4 -4
- data/spec/whois/record_spec.rb +11 -9
- data/spec/whois/server/adapters/afilias_spec.rb +4 -4
- data/spec/whois/server/adapters/arin_spec.rb +9 -10
- data/spec/whois/server/adapters/arpa_spec.rb +2 -2
- data/spec/whois/server/adapters/base_spec.rb +13 -13
- data/spec/whois/server/adapters/formatted_spec.rb +8 -8
- data/spec/whois/server/adapters/none_spec.rb +2 -2
- data/spec/whois/server/adapters/not_implemented_spec.rb +4 -4
- data/spec/whois/server/adapters/standard_spec.rb +5 -5
- data/spec/whois/server/adapters/verisign_spec.rb +5 -5
- data/spec/whois/server/adapters/web_spec.rb +4 -4
- data/spec/whois/server/socket_handler_spec.rb +7 -5
- data/spec/whois/server_spec.rb +31 -29
- data/spec/whois/{errors_spec.rb → web_interface_error_spec.rb} +4 -4
- data/spec/whois/whois_spec.rb +3 -3
- data/whois.gemspec +10 -10
- metadata +16 -11
- data/.travis.yml +0 -18
- data/bin/setup +0 -8
- data/tasks/spec.rake +0 -199
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -22,9 +24,7 @@ module Whois
|
|
22
24
|
@query_handler ||= SocketHandler.new
|
23
25
|
end
|
24
26
|
|
25
|
-
|
26
|
-
@query_handler = handler
|
27
|
-
end
|
27
|
+
attr_writer :query_handler
|
28
28
|
end
|
29
29
|
|
30
30
|
# Default WHOIS request port.
|
@@ -48,15 +48,10 @@ module Whois
|
|
48
48
|
attr_reader :buffer
|
49
49
|
|
50
50
|
|
51
|
-
# @param [Symbol] type
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# @param [
|
55
|
-
# The allocation, range or hostname, this server is responsible for.
|
56
|
-
# @param [String, nil] host
|
57
|
-
# The server hostname. Use nil if unknown or not available.
|
58
|
-
# @param [Hash] options Optional adapter properties.
|
59
|
-
#
|
51
|
+
# @param type [Symbol] the type of WHOIS adapter to define. Known values are :tld, :ipv4, :ipv6,
|
52
|
+
# @param allocation [String] the allocation, range or hostname, this server is responsible for.
|
53
|
+
# @param host [String, nil] the server hostname. Use nil if unknown or not available.
|
54
|
+
# @param options [Hash] optional adapter properties
|
60
55
|
def initialize(type, allocation, host, options = {})
|
61
56
|
@type = type
|
62
57
|
@allocation = allocation
|
@@ -66,53 +61,44 @@ module Whois
|
|
66
61
|
|
67
62
|
# Checks self and other for equality.
|
68
63
|
#
|
69
|
-
# @param [The Whois::Server::Adapters::Base]
|
70
|
-
# @return [Boolean]
|
64
|
+
# @param other [The Whois::Server::Adapters::Base]
|
65
|
+
# @return [Boolean] true if the other is the same object,
|
71
66
|
# or <tt>other</tt> attributes matches this object attributes.
|
72
|
-
#
|
73
67
|
def ==(other)
|
74
|
-
(
|
75
|
-
self.equal?(other)
|
76
|
-
) || (
|
68
|
+
equal?(other) || (
|
77
69
|
other.is_a?(self.class) &&
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
type == other.type &&
|
71
|
+
allocation == other.allocation &&
|
72
|
+
host == other.host &&
|
73
|
+
options == other.options
|
82
74
|
)
|
83
75
|
end
|
84
76
|
|
85
|
-
|
77
|
+
alias eql? ==
|
86
78
|
|
87
79
|
|
88
80
|
# Merges given +settings+ into current {#options}.
|
89
81
|
#
|
90
|
-
# @param [Hash]
|
91
|
-
# @return [Hash]
|
92
|
-
#
|
82
|
+
# @param settings [Hash]
|
83
|
+
# @return [Hash] the updated options for this object
|
93
84
|
def configure(settings)
|
94
85
|
@host = settings[:host] if settings[:host]
|
95
86
|
options.merge!(settings)
|
96
87
|
end
|
97
88
|
|
98
89
|
|
99
|
-
# Performs a Whois lookup for <tt>string</tt>
|
100
|
-
# using the current server adapter.
|
90
|
+
# Performs a Whois lookup for <tt>string</tt> using the current server adapter.
|
101
91
|
#
|
102
|
-
# Internally, this method calls {#request}
|
103
|
-
# using the Template Method design pattern.
|
92
|
+
# Internally, this method calls {#request} using the Template Method design pattern.
|
104
93
|
#
|
105
94
|
# server.lookup("google.com")
|
106
95
|
# # => Whois::Record
|
107
96
|
#
|
108
|
-
# @param [String]
|
97
|
+
# @param string [String] the string to query
|
109
98
|
# @return [Whois::Record]
|
110
|
-
#
|
111
99
|
def lookup(string)
|
112
|
-
buffer_start
|
113
|
-
|
114
|
-
Whois::Record.new(self, buffer.dup)
|
115
|
-
end
|
100
|
+
parts = buffer_start { request(string) }
|
101
|
+
Whois::Record.new(self, parts)
|
116
102
|
end
|
117
103
|
|
118
104
|
# Performs the real WHOIS request.
|
@@ -121,11 +107,10 @@ module Whois
|
|
121
107
|
# it is intended to be overwritten in the concrete subclasses.
|
122
108
|
# This is the heart of the Template Method design pattern.
|
123
109
|
#
|
124
|
-
# @param [String]
|
110
|
+
# @param string [String] the string to query
|
125
111
|
# @return [void]
|
126
112
|
# @raise [NotImplementedError]
|
127
113
|
# @abstract
|
128
|
-
#
|
129
114
|
def request(string)
|
130
115
|
raise NotImplementedError
|
131
116
|
end
|
@@ -149,6 +134,7 @@ module Whois
|
|
149
134
|
def buffer_start
|
150
135
|
@buffer ||= []
|
151
136
|
yield(@buffer)
|
137
|
+
@buffer.dup
|
152
138
|
ensure
|
153
139
|
@buffer.clear
|
154
140
|
end
|
@@ -183,7 +169,7 @@ module Whois
|
|
183
169
|
self.class.query_handler.call(query, *args)
|
184
170
|
end
|
185
171
|
|
186
|
-
alias
|
172
|
+
alias query_the_socket query
|
187
173
|
|
188
174
|
end
|
189
175
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -47,7 +49,7 @@ module Whois
|
|
47
49
|
#
|
48
50
|
def request(string)
|
49
51
|
options[:format] || raise(ServerError, "Missing mandatory :format option for adapter `Formatted'")
|
50
|
-
response = query_the_socket(
|
52
|
+
response = query_the_socket(format(options[:format], string), host)
|
51
53
|
buffer_append response, host
|
52
54
|
end
|
53
55
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -56,4 +58,4 @@ module Whois
|
|
56
58
|
|
57
59
|
end
|
58
60
|
end
|
59
|
-
end
|
61
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -40,6 +42,7 @@ module Whois
|
|
40
42
|
|
41
43
|
def extract_referral(response)
|
42
44
|
return unless (match = response.match(/Registrar WHOIS Server:(.+?)$/))
|
45
|
+
|
43
46
|
server = match[match.size - 1].strip
|
44
47
|
server.empty? ? nil : server
|
45
48
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -22,9 +24,9 @@ module Whois
|
|
22
24
|
# Array of connection errors to rescue
|
23
25
|
# and wrap into a {Whois::ConnectionError}
|
24
26
|
RESCUABLE_CONNECTION_ERRORS = [
|
25
|
-
|
26
|
-
|
27
|
-
]
|
27
|
+
SystemCallError,
|
28
|
+
SocketError,
|
29
|
+
].freeze
|
28
30
|
|
29
31
|
# Performs the Socket request.
|
30
32
|
#
|
@@ -36,8 +38,8 @@ module Whois
|
|
36
38
|
#
|
37
39
|
def call(query, *args)
|
38
40
|
execute(query, *args)
|
39
|
-
rescue *RESCUABLE_CONNECTION_ERRORS =>
|
40
|
-
raise ConnectionError, "#{
|
41
|
+
rescue *RESCUABLE_CONNECTION_ERRORS => e
|
42
|
+
raise ConnectionError, "#{e.class}: #{e.message}"
|
41
43
|
end
|
42
44
|
|
43
45
|
# Executes the low-level Socket connection.
|
data/lib/whois/server.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#--
|
3
4
|
# Ruby Whois
|
4
5
|
#
|
5
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
6
7
|
#
|
7
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
8
9
|
#++
|
9
10
|
|
10
11
|
|
11
12
|
require 'ipaddr'
|
12
13
|
require 'json'
|
13
|
-
require
|
14
|
+
require "whois/server/adapters/base"
|
15
|
+
require "whois/server/adapters/arin"
|
16
|
+
require "whois/server/adapters/arpa"
|
17
|
+
require "whois/server/adapters/afilias"
|
18
|
+
require "whois/server/adapters/formatted"
|
19
|
+
require "whois/server/adapters/none"
|
20
|
+
require "whois/server/adapters/not_implemented"
|
21
|
+
require "whois/server/adapters/standard"
|
22
|
+
require "whois/server/adapters/verisign"
|
23
|
+
require "whois/server/adapters/web"
|
14
24
|
|
15
25
|
|
16
26
|
module Whois
|
@@ -26,25 +36,15 @@ module Whois
|
|
26
36
|
# WHOIS server adapters. Each adapter is a subclass of {Whois::Server::Adapters::Base},
|
27
37
|
# customized to handle WHOIS queries for a type or a group of servers.
|
28
38
|
module Adapters
|
29
|
-
autoload :Base, "whois/server/adapters/base"
|
30
|
-
autoload :Arin, "whois/server/adapters/arin"
|
31
|
-
autoload :Arpa, "whois/server/adapters/arpa"
|
32
|
-
autoload :Afilias, "whois/server/adapters/afilias"
|
33
|
-
autoload :Formatted, "whois/server/adapters/formatted"
|
34
|
-
autoload :None, "whois/server/adapters/none"
|
35
|
-
autoload :NotImplemented, "whois/server/adapters/not_implemented"
|
36
|
-
autoload :Standard, "whois/server/adapters/standard"
|
37
|
-
autoload :Verisign, "whois/server/adapters/verisign"
|
38
|
-
autoload :Web, "whois/server/adapters/web"
|
39
39
|
end
|
40
40
|
|
41
41
|
# @return [Array<Symbol>] the definition types
|
42
42
|
TYPES = [
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
TYPE_TLD = :tld,
|
44
|
+
TYPE_IPV4 = :ipv4,
|
45
|
+
TYPE_IPV6 = :ipv6,
|
46
|
+
TYPE_ASN16 = :asn16,
|
47
|
+
TYPE_ASN32 = :asn32,
|
48
48
|
].freeze
|
49
49
|
|
50
50
|
# Empty hash constant used to save allocation for definitions with empty settings.
|
@@ -67,7 +67,7 @@ module Whois
|
|
67
67
|
# @return [void]
|
68
68
|
def load_definitions
|
69
69
|
clear_definitions
|
70
|
-
Dir[File.expand_path(
|
70
|
+
Dir[File.expand_path('../../data/*.json', __dir__)].each { |f| load_json(f) }
|
71
71
|
end
|
72
72
|
|
73
73
|
# Loads the definitions from a JSON file.
|
@@ -77,16 +77,17 @@ module Whois
|
|
77
77
|
# @return [void]
|
78
78
|
def load_json(file)
|
79
79
|
type = File.basename(file, File.extname(file)).to_sym
|
80
|
-
JSON.
|
80
|
+
JSON.parse(File.read(file)).each do |allocation, settings|
|
81
81
|
next if allocation == "_"
|
82
|
+
|
82
83
|
settings.reject! { |k, _| k.start_with?("_") }
|
83
84
|
host = settings.delete("host")
|
84
85
|
host = intern_string(host) if host
|
85
86
|
options = if settings.empty?
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
EMPTY_HASH
|
88
|
+
else
|
89
|
+
settings.map { |k, v| [k.to_sym, v.is_a?(String) ? intern_string(v) : v] }.to_h.freeze
|
90
|
+
end
|
90
91
|
define(type, allocation, host, options)
|
91
92
|
end
|
92
93
|
end
|
@@ -112,7 +113,7 @@ module Whois
|
|
112
113
|
#
|
113
114
|
def definitions(type)
|
114
115
|
TYPES.include?(type) or
|
115
|
-
|
116
|
+
raise(ArgumentError, "`#{type}` is not a valid definition type")
|
116
117
|
|
117
118
|
_definitions(type).values
|
118
119
|
end
|
@@ -156,7 +157,7 @@ module Whois
|
|
156
157
|
#
|
157
158
|
def define(type, allocation, host, options = EMPTY_HASH)
|
158
159
|
TYPES.include?(type) or
|
159
|
-
|
160
|
+
raise(ArgumentError, "`#{type}` is not a valid definition type")
|
160
161
|
|
161
162
|
_definitions(type)[allocation] = [allocation, host, options.freeze]
|
162
163
|
end
|
@@ -234,19 +235,13 @@ module Whois
|
|
234
235
|
# but the object type doesn't have any supported WHOIS adapter associated.
|
235
236
|
def guess(string)
|
236
237
|
# Top Level Domain match
|
237
|
-
if matches_tld?(string)
|
238
|
-
return factory(:tld, ".", "whois.iana.org")
|
239
|
-
end
|
238
|
+
return factory(:tld, ".", "whois.iana.org") if matches_tld?(string)
|
240
239
|
|
241
240
|
# IP address (secure match)
|
242
|
-
if matches_ip?(string)
|
243
|
-
return find_for_ip(string)
|
244
|
-
end
|
241
|
+
return find_for_ip(string) if matches_ip?(string)
|
245
242
|
|
246
243
|
# Email Address (secure match)
|
247
|
-
if matches_email?(string)
|
248
|
-
return find_for_email(string)
|
249
|
-
end
|
244
|
+
return find_for_email(string) if matches_email?(string)
|
250
245
|
|
251
246
|
# Domain Name match
|
252
247
|
if (server = find_for_domain(string))
|
@@ -254,9 +249,7 @@ module Whois
|
|
254
249
|
end
|
255
250
|
|
256
251
|
# ASN match
|
257
|
-
if matches_asn?(string)
|
258
|
-
return find_for_asn(string)
|
259
|
-
end
|
252
|
+
return find_for_asn(string) if matches_asn?(string)
|
260
253
|
|
261
254
|
# Game Over
|
262
255
|
raise ServerNotFound, "Unable to find a WHOIS server for `#{string}'"
|
@@ -276,12 +269,11 @@ module Whois
|
|
276
269
|
ip = IPAddr.new(string)
|
277
270
|
type = ip.ipv4? ? TYPE_IPV4 : TYPE_IPV6
|
278
271
|
_definitions(type).each do |_, definition|
|
279
|
-
if IPAddr.new(definition.first).include?(ip)
|
280
|
-
return factory(type, *definition)
|
281
|
-
end
|
272
|
+
return factory(type, *definition) if IPAddr.new(definition.first).include?(ip)
|
282
273
|
end
|
283
274
|
rescue ArgumentError
|
284
275
|
# continue
|
276
|
+
nil
|
285
277
|
end
|
286
278
|
raise AllocationUnknown, "IP Allocation for `#{string}' unknown"
|
287
279
|
end
|
@@ -304,7 +296,7 @@ module Whois
|
|
304
296
|
token = string
|
305
297
|
defs = _definitions(TYPE_TLD)
|
306
298
|
|
307
|
-
while token != ""
|
299
|
+
while token != ""
|
308
300
|
if (found = defs[token])
|
309
301
|
return factory(:tld, *found)
|
310
302
|
else
|
@@ -328,7 +320,7 @@ module Whois
|
|
328
320
|
# that matches one of the existing server definitions.
|
329
321
|
def find_for_asn(string)
|
330
322
|
asn = string[/\d+/].to_i
|
331
|
-
asn_type = asn <=
|
323
|
+
asn_type = asn <= 65_535 ? TYPE_ASN16 : TYPE_ASN32
|
332
324
|
_definitions(asn_type).each do |_, definition|
|
333
325
|
if (range = definition.first.split.map(&:to_i)) && asn >= range.first && asn <= range.last
|
334
326
|
return factory(asn_type, *definition)
|
@@ -379,9 +371,10 @@ module Whois
|
|
379
371
|
end
|
380
372
|
|
381
373
|
def valid_ipv4?(addr)
|
382
|
-
if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z
|
383
|
-
return
|
374
|
+
if (m = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/.match(addr))
|
375
|
+
return m.captures.all? { |i| i.to_i < 256 }
|
384
376
|
end
|
377
|
+
|
385
378
|
false
|
386
379
|
end
|
387
380
|
|
@@ -391,9 +384,10 @@ module Whois
|
|
391
384
|
return true if addr.match?(/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
|
392
385
|
return true if addr.match?(/\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
|
393
386
|
# IPv6 (IPv4 compat)
|
394
|
-
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?(
|
395
|
-
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(
|
396
|
-
return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(
|
387
|
+
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
388
|
+
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
389
|
+
return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
390
|
+
|
397
391
|
false
|
398
392
|
end
|
399
393
|
|
data/lib/whois/version.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
10
12
|
module Whois
|
11
13
|
# The current library version.
|
12
|
-
VERSION = "5.
|
14
|
+
VERSION = "5.1.1"
|
13
15
|
end
|
data/lib/whois.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Ruby Whois
|
3
5
|
#
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
5
7
|
#
|
6
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
7
9
|
#++
|
8
10
|
|
9
11
|
|
@@ -35,21 +37,21 @@ module Whois
|
|
35
37
|
Client.new.lookup(object)
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
alias whois lookup
|
39
41
|
|
40
42
|
|
41
43
|
# @deprecated
|
42
44
|
def available?(object)
|
43
45
|
unless defined? Whois::Parser
|
44
46
|
warn("Whois.available? requires the gem `whois-parser`")
|
45
|
-
return
|
47
|
+
return false
|
46
48
|
end
|
47
49
|
|
48
|
-
deprecate(%
|
50
|
+
deprecate(%{Whois.available? is deprecated. Call Whois.whois("#{object}").parser.available?})
|
49
51
|
|
50
52
|
result = lookup(object).parser.available?
|
51
53
|
if result.nil?
|
52
|
-
warn "This method is not supported for this kind of object.\n"
|
54
|
+
warn "This method is not supported for this kind of object.\n" \
|
53
55
|
"Use Whois.lookup('#{object}') instead."
|
54
56
|
end
|
55
57
|
result
|
@@ -59,14 +61,14 @@ module Whois
|
|
59
61
|
def registered?(object)
|
60
62
|
unless defined? Whois::Parser
|
61
63
|
warn("Whois.registered? requires the gem `whois-parser`")
|
62
|
-
return
|
64
|
+
return false
|
63
65
|
end
|
64
66
|
|
65
|
-
deprecate(%
|
67
|
+
deprecate(%{Whois.registered? is deprecated. Call Whois.whois("#{object}").parser.registered?})
|
66
68
|
|
67
69
|
result = lookup(object).parser.registered?
|
68
70
|
if result.nil?
|
69
|
-
warn "This method is not supported for this kind of object.\n"
|
71
|
+
warn "This method is not supported for this kind of object.\n" \
|
70
72
|
"Use Whois.lookup('#{object}') instead."
|
71
73
|
end
|
72
74
|
result
|
@@ -87,9 +89,9 @@ module Whois
|
|
87
89
|
# @api private
|
88
90
|
# @private
|
89
91
|
def bug!(error, message)
|
90
|
-
raise error, message.dup
|
91
|
-
|
92
|
-
|
92
|
+
raise error, message.dup <<
|
93
|
+
" Please report the issue at " \
|
94
|
+
"http://github.com/weppos/whois/issues"
|
93
95
|
end
|
94
96
|
|
95
97
|
|
@@ -107,10 +109,10 @@ module Whois
|
|
107
109
|
end
|
108
110
|
|
109
111
|
def extract_callstack(callstack)
|
110
|
-
gem_root = File.expand_path(
|
112
|
+
gem_root = "#{File.expand_path('../..', __dir__)}/"
|
111
113
|
offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
|
112
114
|
if offending_line
|
113
|
-
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
115
|
+
if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
|
114
116
|
md.captures
|
115
117
|
else
|
116
118
|
offending_line
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois do
|
4
|
-
|
5
|
-
let(:response) { "Domain: example.it\nStatus: AVAILABLE\n" }
|
6
|
+
let(:response) { "Domain: example.it\nStatus: AVAILABLE\n" }
|
6
7
|
|
7
8
|
describe "Basic WHOIS querying and parsing" do
|
8
|
-
it "
|
9
|
+
it "queries and returns a record" do
|
9
10
|
with_definitions do
|
10
11
|
Whois::Server.define(:tld, "it", "whois.nic.it")
|
11
12
|
expect(Whois::Server::Adapters::Standard.query_handler).to receive(:call)
|
@@ -32,7 +33,7 @@ describe Whois do
|
|
32
33
|
.with("example.it", "whois.nic.it", 43, "192.168.1.1", 3000)
|
33
34
|
.and_return(response)
|
34
35
|
|
35
|
-
client = Whois::Client.new(:
|
36
|
+
client = Whois::Client.new(bind_host: "192.168.1.1", bind_port: 3000)
|
36
37
|
client.lookup("example.it")
|
37
38
|
end
|
38
39
|
end
|
@@ -46,7 +47,7 @@ describe Whois do
|
|
46
47
|
.with("example.it", "whois.nic.it", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, 3000)
|
47
48
|
.and_return(response)
|
48
49
|
|
49
|
-
client = Whois::Client.new(:
|
50
|
+
client = Whois::Client.new(bind_port: 3000)
|
50
51
|
client.lookup("example.it")
|
51
52
|
end
|
52
53
|
end
|
@@ -60,7 +61,7 @@ describe Whois do
|
|
60
61
|
.with("example.it", "whois.example.com", 43)
|
61
62
|
.and_return(response)
|
62
63
|
|
63
|
-
client = Whois::Client.new(:
|
64
|
+
client = Whois::Client.new(host: "whois.example.com")
|
64
65
|
record = client.lookup("example.it")
|
65
66
|
|
66
67
|
expect(record.parts.size).to eq(1)
|
@@ -69,5 +70,4 @@ describe Whois do
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
73
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec'
|
2
4
|
require 'whois'
|
3
5
|
|
4
|
-
unless defined?(SPEC_ROOT)
|
5
|
-
SPEC_ROOT = File.expand_path("../", __FILE__)
|
6
|
-
end
|
6
|
+
SPEC_ROOT = File.expand_path(__dir__) unless defined?(SPEC_ROOT)
|
7
7
|
|
8
8
|
# The fixtures are UTF-8 encoded.
|
9
9
|
# Make sure Ruby uses the proper encoding.
|
@@ -12,7 +12,7 @@ Encoding.default_internal = Encoding::UTF_8
|
|
12
12
|
|
13
13
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
14
14
|
# in spec/support/ and its subdirectories.
|
15
|
-
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }
|
15
|
+
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].sort.each { |f| require f }
|
16
16
|
|
17
17
|
RSpec.configure do |config|
|
18
18
|
config.mock_with :rspec
|