dnsbl-client 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4e20ce5cce11180724a890fa7ffd37a5d0010e7347d032387668cafc29d8ad8
4
- data.tar.gz: 17b17dc71cf73c23cd68dd72fe268090e4ee67c933cf26783d91d82a51493a82
3
+ metadata.gz: 8782496924ce9d3fcf9231060e3182203a8e8886a7a4195d75eacb7abed9463c
4
+ data.tar.gz: 7c95c6bcd94468c2ac7a58c4db8d4c21c2bff33b8d5afff7d07c0bb2afb08f02
5
5
  SHA512:
6
- metadata.gz: 89452e4db2cab30c21be082070df59cb7a43043332c7e5565c11b990453c977fda18c173434d1b1a3db9c06d4bf24152fe0602a2e0caf5c60f26bcf23a0a720a
7
- data.tar.gz: bde3f216674c6fc7ed6432616b16157da78eeb18a2fcc5000229035268884ea0c0af2b5c4891bf5a4a2bfd8a423f8fb34eaacd85eb3bd0251a2d2e21d8e37dd4
6
+ metadata.gz: '0954fde62af63a2216af0e6107e2bb162604eeb703d70cc9b91f861373c101f35c95e350102343db62667efd000171bb680c0b9d73b538aee52e979b7dc343fa'
7
+ data.tar.gz: '01490c656455fd58c20f2e407f543c89cc2c7687d6581095b6bb0438e2e1c8ffa35535bd685a46277deeef3efb51bd4bc8f34885866cedcfa36b984caf797a6d'
data/bin/dnsbl-client CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'dnsbl/client'
3
3
 
4
4
  c = DNSBL::Client.new
5
+ c.first_only = true
5
6
 
6
7
  if ARGV.length > 0
7
8
  c.lookup(ARGV).each do |res|
data/data/dnsbl.yaml CHANGED
File without changes
File without changes
data/data/two-level-tlds CHANGED
File without changes
data/lib/dnsbl/client.rb CHANGED
@@ -5,12 +5,13 @@ require 'resolv'
5
5
  require 'socket'
6
6
  require 'thread'
7
7
  require 'yaml'
8
+ require 'ipaddr'
8
9
 
9
10
  # This is a monkeypatch for the built-in Ruby DNS resolver to specify nameservers
10
11
  class Resolv::DNS::Config
11
12
  # Monkeypatch the nameservers to set a default if there are no defined nameservers
12
13
  def nameservers
13
- return @nameservers if @nameservers
14
+ return @nameservers if defined?(@nameservers)
14
15
 
15
16
  lazy_initialize
16
17
  if self.respond_to? :nameserver_port
@@ -41,6 +42,8 @@ module DNSBL # :nodoc:
41
42
  two_level_tldfile = File.expand_path('../../../data', __FILE__)+"/two-level-tlds",
42
43
  three_level_tldfile = File.expand_path('../../../data', __FILE__)+"/three-level-tlds")
43
44
  @dnsbls = config
45
+ @timeout = 1.5
46
+ @first_only = false
44
47
  @two_level_tld = []
45
48
  @three_level_tld = []
46
49
  File.open(two_level_tldfile).readlines.each do |l|
@@ -60,6 +63,14 @@ module DNSBL # :nodoc:
60
63
  @socket_index = 0
61
64
  end
62
65
 
66
+ def timeout=(timeout_seconds)
67
+ @timeout = timeout_seconds
68
+ end
69
+
70
+ def first_only=(first_only_boolean)
71
+ @first_only = first_only_boolean
72
+ end
73
+
63
74
  # sets the nameservers used for performing DNS lookups in round-robin fashion
64
75
  def nameservers=(ns=Resolv::DNS::Config.new.nameservers)
65
76
  @sockets.each do |s|
@@ -108,7 +119,8 @@ module DNSBL # :nodoc:
108
119
  def _encode_query(item,itemtype,domain,apikey=nil)
109
120
  label = nil
110
121
  if itemtype == 'ip'
111
- label = item.split(/\./).reverse.join(".")
122
+ ip = IPAddr.new(item)
123
+ label = ip.reverse.gsub('.ip6.arpa', '').gsub('.in-addr.arpa', '')
112
124
  elsif itemtype == 'domain'
113
125
  label = normalize(item)
114
126
  end
@@ -142,6 +154,8 @@ module DNSBL # :nodoc:
142
154
  @starttime = Time.now.to_f
143
155
  # determine the type of query
144
156
  itemtype = (item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? 'ip' : 'domain'
157
+ itemtype = (item =~ /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/) ? 'ip' : itemtype
158
+
145
159
  # for each dnsbl that supports our type, create the DNS query packet and send it
146
160
  # rotate across our configured name servers and increment sent
147
161
  @dnsbls.each do |name,config|
@@ -160,11 +174,12 @@ module DNSBL # :nodoc:
160
174
  end
161
175
  # while we still expect answers
162
176
  while sent > 0
163
- # wait on the socket for maximally 1.5 seconds
164
- r,_,_ = IO.select(@sockets,nil,nil,1.5)
177
+ # wait on the socket for maximally @timeout seconds
178
+ r,_,_ = IO.select(@sockets,nil,nil,@timeout)
165
179
  # if we time out, break out of the loop
166
180
  break unless r
167
181
  # for each reply, decode it and receive results, decrement the pending answers
182
+ first_only = false
168
183
  r.each do |s|
169
184
  begin
170
185
  response = _decode_response(s.recv(4096))
@@ -174,7 +189,14 @@ module DNSBL # :nodoc:
174
189
  puts e.backtrace.join("\n")
175
190
  end
176
191
  sent -= 1
192
+ if @first_only
193
+ first_only = true
194
+ break
195
+ end
177
196
  end
197
+ if first_only
198
+ break
199
+ end
178
200
  end
179
201
  end
180
202
  results
@@ -1,6 +1,6 @@
1
1
  module DNSBL # :nodoc:
2
2
  class Client
3
3
  # Current version of the dnsbl-client gem
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
5
5
  end
6
6
  end
data/test/helper.rb CHANGED
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsbl-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler