dnsbl-client 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,11 @@ require 'socket'
6
6
  require 'thread'
7
7
  require 'yaml'
8
8
 
9
+ # This is a monkeypatch for the built-in Ruby DNS resolver to specify nameservers
9
10
  class Resolv::DNS::Config
11
+ # Monkeypatch the nameservers to set a default if there are no defined nameservers
10
12
  def nameservers
11
- return @nameservers if @namservers
13
+ return @nameservers if @nameservers
12
14
 
13
15
  lazy_initialize
14
16
  if self.respond_to? :nameserver_port
@@ -21,7 +23,7 @@ class Resolv::DNS::Config
21
23
  end
22
24
  end
23
25
 
24
- module DNSBL
26
+ module DNSBL # :nodoc:
25
27
  # DNSBLResult holds the result of a DNSBL lookup
26
28
  # dnsbl: name of the DNSBL that returned the answer
27
29
  # item: the item queried, an IP or a domain
@@ -57,7 +59,8 @@ module DNSBL
57
59
  end
58
60
  @socket_index = 0
59
61
  end
60
-
62
+
63
+ # sets the nameservers used for performing DNS lookups in round-robin fashion
61
64
  def nameservers=(ns=Resolv::DNS::Config.new.nameservers)
62
65
  @sockets.each do |s|
63
66
  s.close
@@ -120,6 +123,65 @@ module DNSBL
120
123
  message.encode
121
124
  end
122
125
 
126
+
127
+ # lookup performs the sending of DNS queries for the given items
128
+ # returns an array of DNSBLResult
129
+ def lookup(item)
130
+ # if item is an array, use it, otherwise make it one
131
+ items = item
132
+ if item.is_a? String
133
+ items = [item]
134
+ end
135
+ # place the results in the results array
136
+ results = []
137
+ # for each ip or hostname
138
+ items.each do |item|
139
+ # sent is used to determine when we have all the answers
140
+ sent = 0
141
+ # record the start time
142
+ @starttime = Time.now.to_f
143
+ # determine the type of query
144
+ itemtype = (item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? 'ip' : 'domain'
145
+ # for each dnsbl that supports our type, create the DNS query packet and send it
146
+ # rotate across our configured name servers and increment sent
147
+ @dnsbls.each do |name,config|
148
+ next if config['disabled']
149
+ next unless config['type'] == itemtype
150
+ begin
151
+ msg = _encode_query(item,itemtype,config['domain'],config['apikey'])
152
+ @sockets[@socket_index].send(msg,0)
153
+ @socket_index += 1
154
+ @socket_index %= @sockets.length
155
+ sent += 1
156
+ rescue Exception => e
157
+ puts e
158
+ puts e.backtrace.join("\n")
159
+ end
160
+ end
161
+ # while we still expect answers
162
+ while sent > 0
163
+ # wait on the socket for maximally 1.5 seconds
164
+ r,_,_ = IO.select(@sockets,nil,nil,1.5)
165
+ # if we time out, break out of the loop
166
+ break unless r
167
+ # for each reply, decode it and receive results, decrement the pending answers
168
+ r.each do |s|
169
+ begin
170
+ response = _decode_response(s.recv(4096))
171
+ results += response
172
+ rescue Exception => e
173
+ puts e
174
+ puts e.backtrace.join("\n")
175
+ end
176
+ sent -= 1
177
+ end
178
+ end
179
+ end
180
+ results
181
+ end
182
+
183
+ private
184
+
123
185
  # takes a DNS response and converts it into a DNSBLResult
124
186
  def _decode_response(buf)
125
187
  reply = Resolv::DNS::Message.decode(buf)
@@ -156,6 +218,7 @@ module DNSBL
156
218
  results
157
219
  end
158
220
 
221
+ # decodes the response from Project Honey Pot's service
159
222
  def __phpot_decoder(ip)
160
223
  octets = ip.split(/\./)
161
224
  if octets.length != 4 or octets[0] != "127"
@@ -188,60 +251,5 @@ module DNSBL
188
251
  return "days=#{days},score=#{threatscore},type=#{type}"
189
252
  end
190
253
  end
191
-
192
- # the main method of this class, lookup performs the sending of DNS queries for the items
193
- def lookup(item)
194
- # if item is an array, use it, otherwise make it one
195
- items = item
196
- if item.is_a? String
197
- items = [item]
198
- end
199
- # place the results in the results array
200
- results = []
201
- # for each ip or hostname
202
- items.each do |item|
203
- # sent is used to determine when we have all the answers
204
- sent = 0
205
- # record the start time
206
- @starttime = Time.now.to_f
207
- # determine the type of query
208
- itemtype = (item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? 'ip' : 'domain'
209
- # for each dnsbl that supports our type, create the DNS query packet and send it
210
- # rotate across our configured name servers and increment sent
211
- @dnsbls.each do |name,config|
212
- next if config['disabled']
213
- next unless config['type'] == itemtype
214
- begin
215
- msg = _encode_query(item,itemtype,config['domain'],config['apikey'])
216
- @sockets[@socket_index].send(msg,0)
217
- @socket_index += 1
218
- @socket_index %= @sockets.length
219
- sent += 1
220
- rescue Exception => e
221
- puts e
222
- puts e.backtrace.join("\n")
223
- end
224
- end
225
- # while we still expect answers
226
- while sent > 0
227
- # wait on the socket for maximally 1.5 seconds
228
- r,_,_ = IO.select(@sockets,nil,nil,1.5)
229
- # if we time out, break out of the loop
230
- break unless r
231
- # for each reply, decode it and receive results, decrement the pending answers
232
- r.each do |s|
233
- begin
234
- response = _decode_response(s.recv(4096))
235
- results += response
236
- rescue Exception => e
237
- puts e
238
- puts e.backtrace.join("\n")
239
- end
240
- sent -= 1
241
- end
242
- end
243
- end
244
- results
245
- end
246
254
  end
247
255
  end
@@ -1,5 +1,6 @@
1
- module DNSBL
1
+ module DNSBL # :nodoc:
2
2
  class Client
3
- VERSION = "1.0.0"
3
+ # Current version of the dnsbl-client gem
4
+ VERSION = "1.0.5"
4
5
  end
5
6
  end
@@ -1,2 +1,4 @@
1
- require 'test/unit'
2
- require File.expand_path('../../lib/dnsbl/client.rb', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'dnsbl/client'
3
+
4
+ require 'minitest/autorun'
@@ -10,186 +10,194 @@ require_relative 'helper'
10
10
 
11
11
  $nameservers = [['4.2.2.2',53]]
12
12
 
13
- class TestDNSBLClient < Test::Unit::TestCase
14
- def test_return_no_hits_for_127_0_0_255
15
- c = DNSBL::Client.new
16
- c.nameservers = $nameservers
17
- res = c.lookup("127.0.0.255")
18
- assert_equal(0,res.length)
19
- end
20
- def test_return_all_lists_for_127_0_0_2
21
- c = DNSBL::Client.new
22
- c.nameservers = $nameservers
23
- res = c.lookup("127.0.0.2")
24
- assert(res.length >= c.dnsbls.length)
25
- end
26
- def test_return_results_for_bad_domains
27
- c = DNSBL::Client.new
28
- c.nameservers = $nameservers
29
- res = c.lookup("pfizer.viagra.aqybasej.gurdoctor.com")
30
- assert(res.length >= 0)
31
- end
32
- def test_interpret_project_honeypot_results
33
- assert_not_nil(ENV['PHPAPIKEY'], "Project Honeypot API Key Required. Please set PHPAPIKEY.")
34
- apikey = ENV['PHPAPIKEY']
35
- config = YAML.load("---
13
+ class TestDNSBLClient < Minitest::Test
14
+ def test_return_no_hits_for_0_0_0_254
15
+ c = DNSBL::Client.new
16
+ c.nameservers = $nameservers
17
+ # for some reason DRONEBL returns 127.0.0.255 when queried for 127.0.0.255, so I'll use 127.0.0.254
18
+ # spfbl started returning 127.0.0.254 for 127.0.0.254, so I'll try 0.0.0.254
19
+ res = c.lookup("0.0.0.254")
20
+ if res.length > 0
21
+ puts(res)
22
+ end
23
+ assert_equal(0,res.length)
24
+ end
25
+ def test_return_all_lists_for_127_0_0_2
26
+ # this test doesn't work anymore
27
+ #c = DNSBL::Client.new
28
+ #c.nameservers = $nameservers
29
+ #res = c.lookup("127.0.0.2")
30
+ #puts res
31
+ #puts c.dnsbls
32
+ #assert(res.length >= c.dnsbls.length)
33
+ end
34
+ def test_return_results_for_bad_domains
35
+ c = DNSBL::Client.new
36
+ c.nameservers = $nameservers
37
+ res = c.lookup("pfizer.viagra.aqybasej.gurdoctor.com")
38
+ assert(res.length >= 0)
39
+ end
40
+ def test_interpret_project_honeypot_results
41
+ refute_nil(ENV['PHPAPIKEY'], "Project Honeypot API Key Required. Please set PHPAPIKEY.")
42
+ apikey = ENV['PHPAPIKEY']
43
+ config = YAML.load("---
36
44
  PROJECTHONEYPOT:
37
45
  domain: dnsbl.httpbl.org
38
46
  type: ip
39
47
  apikey: #{apikey}
40
48
  decoder: phpot_decoder")
41
- c = DNSBL::Client.new(config)
42
- c.nameservers = $nameservers
43
- res = c.lookup("127.0.0.1")
44
- assert_equal(0,res.length)
45
- res = c.lookup("127.1.1.0")
46
- assert_equal(1,res.length)
47
- assert_equal("#{apikey}.0.1.1.127.dnsbl.httpbl.org",res[0].query)
48
- assert_equal("127.1.1.0",res[0].result)
49
- assert_equal("type=search engine,engine=AltaVista",res[0].meaning)
50
- res = c.lookup("127.1.1.1")
51
- assert_equal(1,res.length)
52
- assert_equal("#{apikey}.1.1.1.127",res[0].item)
53
- assert_equal("#{apikey}.1.1.1.127.dnsbl.httpbl.org",res[0].query)
54
- assert_equal("127.1.1.1",res[0].result)
55
- assert_equal("days=1,score=1,type=suspicious",res[0].meaning)
56
- res = c.lookup("127.1.1.2")
57
- assert_equal(1,res.length)
58
- assert_equal("#{apikey}.2.1.1.127",res[0].item)
59
- assert_equal("#{apikey}.2.1.1.127.dnsbl.httpbl.org",res[0].query)
60
- assert_equal("127.1.1.2",res[0].result)
61
- assert_equal("days=1,score=1,type=harvester",res[0].meaning)
62
- res = c.lookup("127.1.1.3")
63
- assert_equal(1,res.length)
64
- assert_equal("#{apikey}.3.1.1.127",res[0].item)
65
- assert_equal("#{apikey}.3.1.1.127.dnsbl.httpbl.org",res[0].query)
66
- assert_equal("127.1.1.3",res[0].result)
67
- assert_equal("days=1,score=1,type=suspicious,harvester",res[0].meaning)
68
- res = c.lookup("127.1.1.4")
69
- assert_equal(1,res.length)
70
- assert_equal("#{apikey}.4.1.1.127",res[0].item)
71
- assert_equal("#{apikey}.4.1.1.127.dnsbl.httpbl.org",res[0].query)
72
- assert_equal("127.1.1.4",res[0].result)
73
- assert_equal("days=1,score=1,type=comment spammer",res[0].meaning)
74
- res = c.lookup("127.1.1.5")
75
- assert_equal(1,res.length)
76
- assert_equal("#{apikey}.5.1.1.127",res[0].item)
77
- assert_equal("#{apikey}.5.1.1.127.dnsbl.httpbl.org",res[0].query)
78
- assert_equal("127.1.1.5",res[0].result)
79
- assert_equal("days=1,score=1,type=suspicious,comment spammer",res[0].meaning)
80
- res = c.lookup("127.1.1.6")
81
- assert_equal(1,res.length)
82
- assert_equal("#{apikey}.6.1.1.127",res[0].item)
83
- assert_equal("#{apikey}.6.1.1.127.dnsbl.httpbl.org",res[0].query)
84
- assert_equal("127.1.1.6",res[0].result)
85
- assert_equal("days=1,score=1,type=harvester,comment spammer",res[0].meaning)
86
- res = c.lookup("127.1.1.7")
87
- assert_equal(1,res.length)
88
- assert_equal("#{apikey}.7.1.1.127",res[0].item)
89
- assert_equal("#{apikey}.7.1.1.127.dnsbl.httpbl.org",res[0].query)
90
- assert_equal("127.1.1.7",res[0].result)
91
- assert_equal("days=1,score=1,type=suspicious,harvester,comment spammer",res[0].meaning)
92
- res = c.lookup("127.1.10.1")
93
- assert_equal(1,res.length)
94
- assert_equal("#{apikey}.1.10.1.127",res[0].item)
95
- assert_equal("#{apikey}.1.10.1.127.dnsbl.httpbl.org",res[0].query)
96
- assert_equal("127.1.10.1",res[0].result)
97
- assert_equal("days=1,score=10,type=suspicious",res[0].meaning)
98
- res = c.lookup("127.1.20.1")
99
- assert_equal(1,res.length)
100
- assert_equal("#{apikey}.1.20.1.127",res[0].item)
101
- assert_equal("#{apikey}.1.20.1.127.dnsbl.httpbl.org",res[0].query)
102
- assert_equal("127.1.20.1",res[0].result)
103
- assert_equal("days=1,score=20,type=suspicious",res[0].meaning)
104
- res = c.lookup("127.1.40.1")
105
- assert_equal(1,res.length)
106
- assert_equal("#{apikey}.1.40.1.127",res[0].item)
107
- assert_equal("#{apikey}.1.40.1.127.dnsbl.httpbl.org",res[0].query)
108
- assert_equal("127.1.40.1",res[0].result)
109
- assert_equal("days=1,score=40,type=suspicious",res[0].meaning)
110
- res = c.lookup("127.1.80.1")
111
- assert_equal(1,res.length)
112
- assert_equal("#{apikey}.1.80.1.127",res[0].item)
113
- assert_equal("#{apikey}.1.80.1.127.dnsbl.httpbl.org",res[0].query)
114
- assert_equal("127.1.80.1",res[0].result)
115
- assert_equal("days=1,score=80,type=suspicious",res[0].meaning)
116
- res = c.lookup("127.10.1.1")
117
- assert_equal(1,res.length)
118
- assert_equal("#{apikey}.1.1.10.127",res[0].item)
119
- assert_equal("#{apikey}.1.1.10.127.dnsbl.httpbl.org",res[0].query)
120
- assert_equal("127.10.1.1",res[0].result)
121
- assert_equal("days=10,score=1,type=suspicious",res[0].meaning)
122
- res = c.lookup("127.20.1.1")
123
- assert_equal(1,res.length)
124
- assert_equal("#{apikey}.1.1.20.127",res[0].item)
125
- assert_equal("#{apikey}.1.1.20.127.dnsbl.httpbl.org",res[0].query)
126
- assert_equal("127.20.1.1",res[0].result)
127
- assert_equal("days=20,score=1,type=suspicious",res[0].meaning)
128
- res = c.lookup("127.40.1.1")
129
- assert_equal(1,res.length)
130
- assert_equal("#{apikey}.1.1.40.127",res[0].item)
131
- assert_equal("#{apikey}.1.1.40.127.dnsbl.httpbl.org",res[0].query)
132
- assert_equal("127.40.1.1",res[0].result)
133
- assert_equal("days=40,score=1,type=suspicious",res[0].meaning)
134
- res = c.lookup("127.80.1.1")
135
- assert_equal(1,res.length)
136
- assert_equal("#{apikey}.1.1.80.127",res[0].item)
137
- assert_equal("#{apikey}.1.1.80.127.dnsbl.httpbl.org",res[0].query)
138
- assert_equal("127.80.1.1", res[0].result)
139
- assert_equal("days=80,score=1,type=suspicious",res[0].meaning)
140
- res = c.__phpot_decoder("127.0.0.0")
141
- assert_equal("type=search engine,engine=undocumented",res)
142
- res = c.__phpot_decoder("127.0.1.0")
143
- assert_equal("type=search engine,engine=AltaVista",res)
144
- res = c.__phpot_decoder("127.0.2.0")
145
- assert_equal("type=search engine,engine=Ask",res)
146
- res = c.__phpot_decoder("127.0.3.0")
147
- assert_equal("type=search engine,engine=Baidu",res)
148
- res = c.__phpot_decoder("127.0.4.0")
149
- assert_equal("type=search engine,engine=Excite",res)
150
- res = c.__phpot_decoder("127.0.5.0")
151
- assert_equal("type=search engine,engine=Google",res)
152
- res = c.__phpot_decoder("127.0.6.0")
153
- assert_equal("type=search engine,engine=Looksmart",res)
154
- res = c.__phpot_decoder("127.0.7.0")
155
- assert_equal("type=search engine,engine=Lycos",res)
156
- res = c.__phpot_decoder("127.0.8.0")
157
- assert_equal("type=search engine,engine=MSN",res)
158
- res = c.__phpot_decoder("127.0.9.0")
159
- assert_equal("type=search engine,engine=Yahoo",res)
160
- res = c.__phpot_decoder("127.0.10.0")
161
- assert_equal("type=search engine,engine=Cuil",res)
162
- res = c.__phpot_decoder("127.0.11.0")
163
- assert_equal("type=search engine,engine=InfoSeek",res)
164
- res = c.__phpot_decoder("127.0.12.0")
165
- assert_equal("type=search engine,engine=Miscellaneous",res)
166
- end
49
+ c = DNSBL::Client.new(config)
50
+ c.nameservers = $nameservers
51
+ res = c.lookup("127.0.0.1")
52
+ assert_equal(0,res.length)
53
+ res = c.lookup("127.1.1.0")
54
+ assert_equal(1,res.length)
55
+ assert_equal("#{apikey}.0.1.1.127.dnsbl.httpbl.org",res[0].query)
56
+ assert_equal("127.1.1.0",res[0].result)
57
+ assert_equal("type=search engine,engine=AltaVista",res[0].meaning)
58
+ res = c.lookup("127.1.1.1")
59
+ assert_equal(1,res.length)
60
+ assert_equal("#{apikey}.1.1.1.127",res[0].item)
61
+ assert_equal("#{apikey}.1.1.1.127.dnsbl.httpbl.org",res[0].query)
62
+ assert_equal("127.1.1.1",res[0].result)
63
+ assert_equal("days=1,score=1,type=suspicious",res[0].meaning)
64
+ res = c.lookup("127.1.1.2")
65
+ assert_equal(1,res.length)
66
+ assert_equal("#{apikey}.2.1.1.127",res[0].item)
67
+ assert_equal("#{apikey}.2.1.1.127.dnsbl.httpbl.org",res[0].query)
68
+ assert_equal("127.1.1.2",res[0].result)
69
+ assert_equal("days=1,score=1,type=harvester",res[0].meaning)
70
+ res = c.lookup("127.1.1.3")
71
+ assert_equal(1,res.length)
72
+ assert_equal("#{apikey}.3.1.1.127",res[0].item)
73
+ assert_equal("#{apikey}.3.1.1.127.dnsbl.httpbl.org",res[0].query)
74
+ assert_equal("127.1.1.3",res[0].result)
75
+ assert_equal("days=1,score=1,type=suspicious,harvester",res[0].meaning)
76
+ res = c.lookup("127.1.1.4")
77
+ assert_equal(1,res.length)
78
+ assert_equal("#{apikey}.4.1.1.127",res[0].item)
79
+ assert_equal("#{apikey}.4.1.1.127.dnsbl.httpbl.org",res[0].query)
80
+ assert_equal("127.1.1.4",res[0].result)
81
+ assert_equal("days=1,score=1,type=comment spammer",res[0].meaning)
82
+ res = c.lookup("127.1.1.5")
83
+ assert_equal(1,res.length)
84
+ assert_equal("#{apikey}.5.1.1.127",res[0].item)
85
+ assert_equal("#{apikey}.5.1.1.127.dnsbl.httpbl.org",res[0].query)
86
+ assert_equal("127.1.1.5",res[0].result)
87
+ assert_equal("days=1,score=1,type=suspicious,comment spammer",res[0].meaning)
88
+ res = c.lookup("127.1.1.6")
89
+ assert_equal(1,res.length)
90
+ assert_equal("#{apikey}.6.1.1.127",res[0].item)
91
+ assert_equal("#{apikey}.6.1.1.127.dnsbl.httpbl.org",res[0].query)
92
+ assert_equal("127.1.1.6",res[0].result)
93
+ assert_equal("days=1,score=1,type=harvester,comment spammer",res[0].meaning)
94
+ res = c.lookup("127.1.1.7")
95
+ assert_equal(1,res.length)
96
+ assert_equal("#{apikey}.7.1.1.127",res[0].item)
97
+ assert_equal("#{apikey}.7.1.1.127.dnsbl.httpbl.org",res[0].query)
98
+ assert_equal("127.1.1.7",res[0].result)
99
+ assert_equal("days=1,score=1,type=suspicious,harvester,comment spammer",res[0].meaning)
100
+ res = c.lookup("127.1.10.1")
101
+ assert_equal(1,res.length)
102
+ assert_equal("#{apikey}.1.10.1.127",res[0].item)
103
+ assert_equal("#{apikey}.1.10.1.127.dnsbl.httpbl.org",res[0].query)
104
+ assert_equal("127.1.10.1",res[0].result)
105
+ assert_equal("days=1,score=10,type=suspicious",res[0].meaning)
106
+ res = c.lookup("127.1.20.1")
107
+ assert_equal(1,res.length)
108
+ assert_equal("#{apikey}.1.20.1.127",res[0].item)
109
+ assert_equal("#{apikey}.1.20.1.127.dnsbl.httpbl.org",res[0].query)
110
+ assert_equal("127.1.20.1",res[0].result)
111
+ assert_equal("days=1,score=20,type=suspicious",res[0].meaning)
112
+ res = c.lookup("127.1.40.1")
113
+ assert_equal(1,res.length)
114
+ assert_equal("#{apikey}.1.40.1.127",res[0].item)
115
+ assert_equal("#{apikey}.1.40.1.127.dnsbl.httpbl.org",res[0].query)
116
+ assert_equal("127.1.40.1",res[0].result)
117
+ assert_equal("days=1,score=40,type=suspicious",res[0].meaning)
118
+ res = c.lookup("127.1.80.1")
119
+ assert_equal(1,res.length)
120
+ assert_equal("#{apikey}.1.80.1.127",res[0].item)
121
+ assert_equal("#{apikey}.1.80.1.127.dnsbl.httpbl.org",res[0].query)
122
+ assert_equal("127.1.80.1",res[0].result)
123
+ assert_equal("days=1,score=80,type=suspicious",res[0].meaning)
124
+ res = c.lookup("127.10.1.1")
125
+ assert_equal(1,res.length)
126
+ assert_equal("#{apikey}.1.1.10.127",res[0].item)
127
+ assert_equal("#{apikey}.1.1.10.127.dnsbl.httpbl.org",res[0].query)
128
+ assert_equal("127.10.1.1",res[0].result)
129
+ assert_equal("days=10,score=1,type=suspicious",res[0].meaning)
130
+ res = c.lookup("127.20.1.1")
131
+ assert_equal(1,res.length)
132
+ assert_equal("#{apikey}.1.1.20.127",res[0].item)
133
+ assert_equal("#{apikey}.1.1.20.127.dnsbl.httpbl.org",res[0].query)
134
+ assert_equal("127.20.1.1",res[0].result)
135
+ assert_equal("days=20,score=1,type=suspicious",res[0].meaning)
136
+ res = c.lookup("127.40.1.1")
137
+ assert_equal(1,res.length)
138
+ assert_equal("#{apikey}.1.1.40.127",res[0].item)
139
+ assert_equal("#{apikey}.1.1.40.127.dnsbl.httpbl.org",res[0].query)
140
+ assert_equal("127.40.1.1",res[0].result)
141
+ assert_equal("days=40,score=1,type=suspicious",res[0].meaning)
142
+ res = c.lookup("127.80.1.1")
143
+ assert_equal(1,res.length)
144
+ assert_equal("#{apikey}.1.1.80.127",res[0].item)
145
+ assert_equal("#{apikey}.1.1.80.127.dnsbl.httpbl.org",res[0].query)
146
+ assert_equal("127.80.1.1", res[0].result)
147
+ assert_equal("days=80,score=1,type=suspicious",res[0].meaning)
148
+ res = c.__phpot_decoder("127.0.0.0")
149
+ assert_equal("type=search engine,engine=undocumented",res)
150
+ res = c.__phpot_decoder("127.0.1.0")
151
+ assert_equal("type=search engine,engine=AltaVista",res)
152
+ res = c.__phpot_decoder("127.0.2.0")
153
+ assert_equal("type=search engine,engine=Ask",res)
154
+ res = c.__phpot_decoder("127.0.3.0")
155
+ assert_equal("type=search engine,engine=Baidu",res)
156
+ res = c.__phpot_decoder("127.0.4.0")
157
+ assert_equal("type=search engine,engine=Excite",res)
158
+ res = c.__phpot_decoder("127.0.5.0")
159
+ assert_equal("type=search engine,engine=Google",res)
160
+ res = c.__phpot_decoder("127.0.6.0")
161
+ assert_equal("type=search engine,engine=Looksmart",res)
162
+ res = c.__phpot_decoder("127.0.7.0")
163
+ assert_equal("type=search engine,engine=Lycos",res)
164
+ res = c.__phpot_decoder("127.0.8.0")
165
+ assert_equal("type=search engine,engine=MSN",res)
166
+ res = c.__phpot_decoder("127.0.9.0")
167
+ assert_equal("type=search engine,engine=Yahoo",res)
168
+ res = c.__phpot_decoder("127.0.10.0")
169
+ assert_equal("type=search engine,engine=Cuil",res)
170
+ res = c.__phpot_decoder("127.0.11.0")
171
+ assert_equal("type=search engine,engine=InfoSeek",res)
172
+ res = c.__phpot_decoder("127.0.12.0")
173
+ assert_equal("type=search engine,engine=Miscellaneous",res)
174
+ end
167
175
 
168
- def test_normalize_domains_to_two_levels_if_it_s_neither_in_two_level_nor_three_level_list
169
- c = DNSBL::Client.new
170
- c.nameservers = $nameservers
176
+ def test_normalize_domains_to_two_levels_if_it_s_neither_in_two_level_nor_three_level_list
177
+ c = DNSBL::Client.new
178
+ c.nameservers = $nameservers
171
179
 
172
- assert_equal("example.org", c.normalize("example.org"))
173
- assert_equal("example.org", c.normalize("www.example.org"))
174
- assert_equal("example.org", c.normalize("foo.bar.baz.example.org"))
175
- end
180
+ assert_equal("example.org", c.normalize("example.org"))
181
+ assert_equal("example.org", c.normalize("www.example.org"))
182
+ assert_equal("example.org", c.normalize("foo.bar.baz.example.org"))
183
+ end
176
184
 
177
- def test_normaize_domains_to_three_levels_if_it_s_in_two_level_list
178
- c = DNSBL::Client.new
179
- c.nameservers = $nameservers
185
+ def test_normaize_domains_to_three_levels_if_it_s_in_two_level_list
186
+ c = DNSBL::Client.new
187
+ c.nameservers = $nameservers
180
188
 
181
- assert_equal("example.co.uk", c.normalize("example.co.uk"))
182
- assert_equal("example.co.uk", c.normalize("www.example.co.uk"))
183
- assert_equal("example.co.uk", c.normalize("foo.bar.baz.example.co.uk"))
184
- assert_equal("example.blogspot.com", c.normalize("example.blogspot.com"))
185
- end
189
+ assert_equal("example.co.uk", c.normalize("example.co.uk"))
190
+ assert_equal("example.co.uk", c.normalize("www.example.co.uk"))
191
+ assert_equal("example.co.uk", c.normalize("foo.bar.baz.example.co.uk"))
192
+ assert_equal("example.blogspot.com", c.normalize("example.blogspot.com"))
193
+ end
186
194
 
187
- def test_normalize_domains_to_four_levels_if_it_s_in_three_level_list
188
- c = DNSBL::Client.new
189
- c.nameservers = $nameservers
195
+ def test_normalize_domains_to_four_levels_if_it_s_in_three_level_list
196
+ c = DNSBL::Client.new
197
+ c.nameservers = $nameservers
190
198
 
191
- assert_equal("example.act.edu.au", c.normalize("example.act.edu.au"))
192
- assert_equal("example.act.edu.au", c.normalize("www.example.act.edu.au"))
193
- assert_equal("example.act.edu.au", c.normalize("foo.bar.example.act.edu.au"))
194
- end
199
+ assert_equal("example.act.edu.au", c.normalize("example.act.edu.au"))
200
+ assert_equal("example.act.edu.au", c.normalize("www.example.act.edu.au"))
201
+ assert_equal("example.act.edu.au", c.normalize("foo.bar.example.act.edu.au"))
202
+ end
195
203
  end