whois 5.1.1 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +3 -3
- data/.github/workflows/release.yml +3 -1
- data/.github/workflows/tests.yml +2 -3
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +11 -87
- data/CHANGELOG.md +19 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/SECURITY.md +24 -0
- data/bin/whoisrb +3 -3
- data/data/tld.json +8 -775
- data/lib/whois/client.rb +2 -2
- data/lib/whois/errors.rb +1 -1
- data/lib/whois/record/part.rb +1 -1
- data/lib/whois/record.rb +2 -2
- data/lib/whois/server/adapters/afilias.rb +1 -1
- data/lib/whois/server/adapters/arin.rb +1 -1
- data/lib/whois/server/adapters/arpa.rb +5 -7
- data/lib/whois/server/adapters/base.rb +4 -4
- data/lib/whois/server/adapters/formatted.rb +1 -1
- data/lib/whois/server/adapters/none.rb +2 -2
- data/lib/whois/server/adapters/not_implemented.rb +2 -2
- data/lib/whois/server/adapters/standard.rb +1 -1
- data/lib/whois/server/adapters/verisign.rb +1 -1
- data/lib/whois/server/adapters/web.rb +2 -2
- data/lib/whois/server/socket_handler.rb +4 -4
- data/lib/whois/server.rb +10 -10
- data/lib/whois/version.rb +2 -2
- data/lib/whois.rb +19 -19
- data/spec/integration/whois_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -3
- data/spec/whois/client_spec.rb +1 -1
- data/spec/whois/record/part_spec.rb +1 -1
- data/spec/whois/record_spec.rb +26 -18
- data/spec/whois/server/adapters/afilias_spec.rb +1 -1
- data/spec/whois/server/adapters/arin_spec.rb +1 -1
- data/spec/whois/server/adapters/arpa_spec.rb +13 -4
- data/spec/whois/server/adapters/base_spec.rb +17 -12
- data/spec/whois/server/adapters/formatted_spec.rb +1 -1
- data/spec/whois/server/adapters/none_spec.rb +1 -1
- data/spec/whois/server/adapters/not_implemented_spec.rb +2 -2
- data/spec/whois/server/adapters/standard_spec.rb +1 -1
- data/spec/whois/server/adapters/verisign_spec.rb +1 -1
- data/spec/whois/server/adapters/web_spec.rb +1 -1
- data/spec/whois/server/socket_handler_spec.rb +2 -2
- data/spec/whois/server_spec.rb +51 -51
- data/spec/whois/web_interface_error_spec.rb +1 -1
- data/spec/whois/whois_spec.rb +1 -1
- data/utils/deftld.rb +0 -1
- data/whois.gemspec +1 -1
- metadata +6 -36
data/lib/whois/client.rb
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
12
|
+
require "timeout"
|
13
13
|
|
14
14
|
|
15
15
|
module Whois
|
data/lib/whois/errors.rb
CHANGED
data/lib/whois/record/part.rb
CHANGED
data/lib/whois/record.rb
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
12
|
+
require "whois/record/part"
|
13
13
|
|
14
14
|
|
15
15
|
module Whois
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
@@ -30,16 +30,14 @@ module Whois
|
|
30
30
|
# "192.in-addr.arpa" => "192.0.0.0"
|
31
31
|
# "in-addr.arpa" => "0.0.0.0"
|
32
32
|
def inaddr_to_ip(string)
|
33
|
-
raise ServerError, "Invalid .in-addr.arpa address" unless string.match?(
|
33
|
+
raise ServerError, "Invalid .in-addr.arpa address" unless string.match?(/\A([0-9]{1,3}\.?){0,4}in-addr\.arpa\z/)
|
34
34
|
|
35
35
|
a, b, c, d = string.scan(/[0-9]{1,3}\./).reverse
|
36
36
|
[a, b, c, d].map do |token|
|
37
37
|
token = (token || 0).to_i
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
raise ServerError, "Invalid .in-addr.arpa token `#{token}'"
|
42
|
-
end
|
38
|
+
raise ServerError, "Invalid .in-addr.arpa token `#{token}'" unless token <= 255 && token >= 0
|
39
|
+
|
40
|
+
token
|
43
41
|
end.join(".")
|
44
42
|
end
|
45
43
|
|
@@ -5,13 +5,13 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
12
|
+
require "whois/record/part"
|
13
|
+
require "whois/record"
|
14
|
+
require "whois/server/socket_handler"
|
15
15
|
|
16
16
|
|
17
17
|
module Whois
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
@@ -36,7 +36,7 @@ module Whois
|
|
36
36
|
#
|
37
37
|
# @raise [Whois::NoInterfaceError] For every request.
|
38
38
|
#
|
39
|
-
def request(
|
39
|
+
def request(_string)
|
40
40
|
raise NoInterfaceError, "This `#{type}' has no whois server"
|
41
41
|
end
|
42
42
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
@@ -22,7 +22,7 @@ module Whois
|
|
22
22
|
#
|
23
23
|
# @raise [Whois::ServerNotImplemented] For every request.
|
24
24
|
#
|
25
|
-
def request(
|
25
|
+
def request(_string)
|
26
26
|
raise ServerNotImplemented, "The `#{host}' feature has not been implemented yet."
|
27
27
|
end
|
28
28
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
@@ -32,7 +32,7 @@ module Whois
|
|
32
32
|
#
|
33
33
|
# @raise [Whois::WebInterfaceError] For every request.
|
34
34
|
#
|
35
|
-
def request(
|
35
|
+
def request(_string)
|
36
36
|
raise WebInterfaceError, options[:url]
|
37
37
|
end
|
38
38
|
|
@@ -5,12 +5,12 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
12
|
+
require "socket"
|
13
|
+
require "whois/errors"
|
14
14
|
|
15
15
|
|
16
16
|
module Whois
|
@@ -58,7 +58,7 @@ module Whois
|
|
58
58
|
client.write("#{query}\r\n") # I could use put(foo) and forget the \n
|
59
59
|
client.read # but write/read is more symmetric than puts/read
|
60
60
|
ensure # and I really want to use read instead of gets.
|
61
|
-
client
|
61
|
+
client&.close # If != client something went wrong.
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
data/lib/whois/server.rb
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
12
|
+
require "ipaddr"
|
13
|
+
require "json"
|
14
14
|
require "whois/server/adapters/base"
|
15
15
|
require "whois/server/adapters/arin"
|
16
16
|
require "whois/server/adapters/arpa"
|
@@ -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.
|
@@ -86,7 +86,7 @@ module Whois
|
|
86
86
|
options = if settings.empty?
|
87
87
|
EMPTY_HASH
|
88
88
|
else
|
89
|
-
settings.
|
89
|
+
settings.to_h { |k, v| [k.to_sym, v.is_a?(String) ? intern_string(v) : v] }.freeze
|
90
90
|
end
|
91
91
|
define(type, allocation, host, options)
|
92
92
|
end
|
@@ -268,7 +268,7 @@ module Whois
|
|
268
268
|
begin
|
269
269
|
ip = IPAddr.new(string)
|
270
270
|
type = ip.ipv4? ? TYPE_IPV4 : TYPE_IPV6
|
271
|
-
_definitions(type).
|
271
|
+
_definitions(type).each_value do |definition|
|
272
272
|
return factory(type, *definition) if IPAddr.new(definition.first).include?(ip)
|
273
273
|
end
|
274
274
|
rescue ArgumentError
|
@@ -283,7 +283,7 @@ module Whois
|
|
283
283
|
# @param string [String]
|
284
284
|
# @raise [Whois::ServerNotSupported]
|
285
285
|
# emails are not supported.
|
286
|
-
def find_for_email(
|
286
|
+
def find_for_email(_string)
|
287
287
|
raise ServerNotSupported, "No WHOIS server is known for email objects"
|
288
288
|
end
|
289
289
|
|
@@ -303,7 +303,7 @@ module Whois
|
|
303
303
|
index = token.index(".")
|
304
304
|
break if index.nil?
|
305
305
|
|
306
|
-
token = token[(index + 1)
|
306
|
+
token = token[(index + 1)..]
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -321,7 +321,7 @@ module Whois
|
|
321
321
|
def find_for_asn(string)
|
322
322
|
asn = string[/\d+/].to_i
|
323
323
|
asn_type = asn <= 65_535 ? TYPE_ASN16 : TYPE_ASN32
|
324
|
-
_definitions(asn_type).
|
324
|
+
_definitions(asn_type).each_value do |definition|
|
325
325
|
if (range = definition.first.split.map(&:to_i)) && asn >= range.first && asn <= range.last
|
326
326
|
return factory(asn_type, *definition)
|
327
327
|
end
|
@@ -363,7 +363,7 @@ module Whois
|
|
363
363
|
end
|
364
364
|
|
365
365
|
def matches_email?(string)
|
366
|
-
string.include?(
|
366
|
+
string.include?("@")
|
367
367
|
end
|
368
368
|
|
369
369
|
def matches_asn?(string)
|
data/lib/whois/version.rb
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
12
|
module Whois
|
13
13
|
# The current library version.
|
14
|
-
VERSION = "
|
14
|
+
VERSION = "6.0.1"
|
15
15
|
end
|
data/lib/whois.rb
CHANGED
@@ -5,15 +5,15 @@
|
|
5
5
|
#
|
6
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
7
7
|
#
|
8
|
-
# Copyright (c) 2009-
|
8
|
+
# Copyright (c) 2009-2024 Simone Carletti <weppos@weppos.net>
|
9
9
|
#++
|
10
10
|
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
12
|
+
require "whois/version"
|
13
|
+
require "whois/errors"
|
14
|
+
require "whois/client"
|
15
|
+
require "whois/server"
|
16
|
+
require "whois/record"
|
17
17
|
|
18
18
|
|
19
19
|
module Whois
|
@@ -74,7 +74,7 @@ module Whois
|
|
74
74
|
result
|
75
75
|
end
|
76
76
|
|
77
|
-
def deprecate(message = nil,
|
77
|
+
def deprecate(message = nil, _callstack = caller)
|
78
78
|
# warn("DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}")
|
79
79
|
warn("DEPRECATION WARNING: #{message}")
|
80
80
|
end
|
@@ -99,24 +99,24 @@ module Whois
|
|
99
99
|
|
100
100
|
def deprecation_caller_message(callstack)
|
101
101
|
file, line, method = extract_callstack(callstack)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
102
|
+
return unless file
|
103
|
+
|
104
|
+
if line && method
|
105
|
+
"(called from #{method} at #{file}:#{line})"
|
106
|
+
else
|
107
|
+
"(called from #{file}:#{line})"
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
def extract_callstack(callstack)
|
112
112
|
gem_root = "#{File.expand_path('../..', __dir__)}/"
|
113
113
|
offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
return unless offending_line
|
115
|
+
|
116
|
+
if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
|
117
|
+
md.captures
|
118
|
+
else
|
119
|
+
offending_line
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe Whois do
|
6
6
|
let(:response) { "Domain: example.it\nStatus: AVAILABLE\n" }
|
@@ -13,7 +13,7 @@ describe Whois do
|
|
13
13
|
.with("example.it", "whois.nic.it", 43)
|
14
14
|
.and_return(response)
|
15
15
|
|
16
|
-
record =
|
16
|
+
record = described_class.lookup("example.it")
|
17
17
|
|
18
18
|
expect(record).to be_a(Whois::Record)
|
19
19
|
# expect(record.available?).to be_truthy
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rspec"
|
4
|
+
require "whois"
|
5
5
|
|
6
6
|
SPEC_ROOT = File.expand_path(__dir__) unless defined?(SPEC_ROOT)
|
7
7
|
|
@@ -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")].
|
15
|
+
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }
|
16
16
|
|
17
17
|
RSpec.configure do |config|
|
18
18
|
config.mock_with :rspec
|
data/spec/whois/client_spec.rb
CHANGED
data/spec/whois/record_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe Whois::Record do
|
6
6
|
subject { described_class.new(server, parts) }
|
@@ -65,64 +65,72 @@ describe Whois::Record do
|
|
65
65
|
one = two = described_class.new(server, parts)
|
66
66
|
|
67
67
|
expect(one == two).to be_truthy
|
68
|
-
expect(one.eql
|
68
|
+
expect(one).to eql(two)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "returns true when other has same class and has the same parts" do
|
72
|
-
one
|
72
|
+
one = described_class.new(server, parts)
|
73
|
+
two = described_class.new(server, parts)
|
73
74
|
|
74
75
|
expect(one == two).to be_truthy
|
75
|
-
expect(one.eql
|
76
|
+
expect(one).to eql(two)
|
76
77
|
end
|
77
78
|
|
78
79
|
it "returns true when other has descendant class and has the same parts" do
|
79
80
|
subklass = Class.new(described_class)
|
80
|
-
one
|
81
|
+
one = described_class.new(server, parts)
|
82
|
+
two = subklass.new(server, parts)
|
81
83
|
|
82
84
|
expect(one == two).to be_truthy
|
83
|
-
expect(one.eql
|
85
|
+
expect(one).to eql(two)
|
84
86
|
end
|
85
87
|
|
86
88
|
it "returns true when other has same class and has equal parts" do
|
87
|
-
one
|
89
|
+
one = described_class.new(server, parts)
|
90
|
+
two = described_class.new(server, parts.dup)
|
88
91
|
|
89
92
|
expect(one == two).to be_truthy
|
90
|
-
expect(one.eql
|
93
|
+
expect(one).to eql(two)
|
91
94
|
end
|
92
95
|
|
93
96
|
it "returns true when other has same class, different server and the same parts" do
|
94
|
-
one
|
97
|
+
one = described_class.new(server, parts)
|
98
|
+
two = described_class.new(nil, parts)
|
95
99
|
|
96
100
|
expect(one == two).to be_truthy
|
97
|
-
expect(one.eql
|
101
|
+
expect(one).to eql(two)
|
98
102
|
end
|
99
103
|
|
100
104
|
it "returns false when other has different class and has the same parts" do
|
101
|
-
one
|
105
|
+
one = described_class.new(server, parts)
|
106
|
+
two = Struct.new(:server, :parts).new(server, parts)
|
102
107
|
|
103
108
|
expect(one == two).to be_falsey
|
104
|
-
expect(one.eql
|
109
|
+
expect(one).not_to eql(two)
|
105
110
|
end
|
106
111
|
|
107
112
|
it "returns false when other has different parts" do
|
108
|
-
one
|
113
|
+
one = described_class.new(server, parts)
|
114
|
+
two = described_class.new(server, [])
|
109
115
|
|
110
116
|
expect(one == two).to be_falsey
|
111
|
-
expect(one.eql
|
117
|
+
expect(one).not_to eql(two)
|
112
118
|
end
|
113
119
|
|
114
120
|
it "returns false when other is string and has the same content" do
|
115
|
-
one
|
121
|
+
one = described_class.new(server, parts)
|
122
|
+
two = described_class.new(server, parts).to_s
|
116
123
|
|
117
124
|
expect(one == two).to be_falsey
|
118
|
-
expect(one.eql
|
125
|
+
expect(one).not_to eql(two)
|
119
126
|
end
|
120
127
|
|
121
128
|
it "returns false when other is string and has different content" do
|
122
|
-
one
|
129
|
+
one = described_class.new(server, parts)
|
130
|
+
two = "different"
|
123
131
|
|
124
132
|
expect(one == two).to be_falsey
|
125
|
-
expect(one.eql
|
133
|
+
expect(one).not_to eql(two)
|
126
134
|
end
|
127
135
|
end
|
128
136
|
|
@@ -1,20 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "whois/server/adapters/arin"
|
5
5
|
|
6
6
|
describe Whois::Server::Adapters::Arpa do
|
7
7
|
let(:definition) { [:tld, ".in-addr.arpa", nil, {}] }
|
8
8
|
|
9
9
|
describe "#lookup" do
|
10
10
|
it "returns the WHOIS record" do
|
11
|
-
response = "Whois Response"
|
12
11
|
server = described_class.new(*definition)
|
13
|
-
expect(Whois::Server::Adapters::Arin.query_handler).to receive(:call)
|
12
|
+
expect(Whois::Server::Adapters::Arin.query_handler).to receive(:call)
|
13
|
+
.with("n + 229.128.in-addr.arpa", "whois.arin.net", 43)
|
14
|
+
.and_return(response = "Whois Response")
|
14
15
|
|
15
16
|
record = server.lookup("229.128.in-addr.arpa")
|
16
17
|
expect(record.to_s).to eq(response)
|
17
18
|
expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.arin.net")])
|
18
19
|
end
|
20
|
+
|
21
|
+
it "discards newlines" do
|
22
|
+
server = described_class.new(*definition)
|
23
|
+
|
24
|
+
expect do
|
25
|
+
server.lookup("229.128.in-addr.arpa\nextra")
|
26
|
+
end.to raise_error(Whois::ServerError, "Invalid .in-addr.arpa address")
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|