dnsbl-client 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +8 -0
  3. data/data/three-level-tlds +2129 -1
  4. data/data/two-level-tlds +1858 -0
  5. data/html/DNSBL.html +98 -0
  6. data/html/DNSBL/Client.html +646 -0
  7. data/html/DNSBL/DNSBLResult.html +114 -0
  8. data/html/README_md.html +141 -0
  9. data/html/Resolv.html +98 -0
  10. data/html/Resolv/DNS.html +98 -0
  11. data/html/Resolv/DNS/Config.html +169 -0
  12. data/html/created.rid +4 -0
  13. data/html/fonts.css +167 -0
  14. data/html/fonts/Lato-Light.ttf +0 -0
  15. data/html/fonts/Lato-LightItalic.ttf +0 -0
  16. data/html/fonts/Lato-Regular.ttf +0 -0
  17. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  18. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  19. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  20. data/html/images/add.png +0 -0
  21. data/html/images/arrow_up.png +0 -0
  22. data/html/images/brick.png +0 -0
  23. data/html/images/brick_link.png +0 -0
  24. data/html/images/bug.png +0 -0
  25. data/html/images/bullet_black.png +0 -0
  26. data/html/images/bullet_toggle_minus.png +0 -0
  27. data/html/images/bullet_toggle_plus.png +0 -0
  28. data/html/images/date.png +0 -0
  29. data/html/images/delete.png +0 -0
  30. data/html/images/find.png +0 -0
  31. data/html/images/loadingAnimation.gif +0 -0
  32. data/html/images/macFFBgHack.png +0 -0
  33. data/html/images/package.png +0 -0
  34. data/html/images/page_green.png +0 -0
  35. data/html/images/page_white_text.png +0 -0
  36. data/html/images/page_white_width.png +0 -0
  37. data/html/images/plugin.png +0 -0
  38. data/html/images/ruby.png +0 -0
  39. data/html/images/tag_blue.png +0 -0
  40. data/html/images/tag_green.png +0 -0
  41. data/html/images/transparent.png +0 -0
  42. data/html/images/wrench.png +0 -0
  43. data/html/images/wrench_orange.png +0 -0
  44. data/html/images/zoom.png +0 -0
  45. data/html/index.html +98 -0
  46. data/html/js/darkfish.js +140 -0
  47. data/html/js/jquery.js +18 -0
  48. data/html/js/navigation.js +142 -0
  49. data/html/js/search.js +109 -0
  50. data/html/js/search_index.js +1 -0
  51. data/html/js/searcher.js +228 -0
  52. data/html/rdoc.css +580 -0
  53. data/html/table_of_contents.html +120 -0
  54. data/lib/dnsbl/client.rb +65 -57
  55. data/lib/dnsbl/client/version.rb +3 -2
  56. metadata +51 -2
@@ -0,0 +1,120 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <link href="./fonts.css" rel="stylesheet">
10
+ <link href="./rdoc.css" rel="stylesheet">
11
+
12
+ <script type="text/javascript">
13
+ var rdoc_rel_prefix = "./";
14
+ </script>
15
+
16
+ <script src="./js/jquery.js"></script>
17
+ <script src="./js/navigation.js"></script>
18
+ <script src="./js/search_index.js"></script>
19
+ <script src="./js/search.js"></script>
20
+ <script src="./js/searcher.js"></script>
21
+ <script src="./js/darkfish.js"></script>
22
+
23
+
24
+ <body id="top" class="table-of-contents">
25
+ <main role="main">
26
+ <h1 class="class">Table of Contents - RDoc Documentation</h1>
27
+
28
+ <h2 id="pages">Pages</h2>
29
+ <ul>
30
+ <li class="file">
31
+ <a href="README_md.html">README</a>
32
+
33
+ <ul>
34
+ <li><a href="README_md.html#label-DNSBL%3A%3AClient">DNSBL::Client</a>
35
+ <li><a href="README_md.html#label-Installation">Installation</a>
36
+ <li><a href="README_md.html#label-Usage">Usage</a>
37
+ <li><a href="README_md.html#label-Contributing">Contributing</a>
38
+ </ul>
39
+ </li>
40
+
41
+ </ul>
42
+
43
+ <h2 id="classes">Classes and Modules</h2>
44
+ <ul>
45
+ <li class="module">
46
+ <a href="DNSBL.html">DNSBL</a>
47
+ </li>
48
+ <li class="class">
49
+ <a href="DNSBL/Client.html">DNSBL::Client</a>
50
+ </li>
51
+ <li class="class">
52
+ <a href="DNSBL/DNSBLResult.html">DNSBL::DNSBLResult</a>
53
+ </li>
54
+ <li class="class">
55
+ <a href="Resolv/DNS/Config.html">Resolv::DNS::Config</a>
56
+ </li>
57
+ </ul>
58
+
59
+ <h2 id="methods">Methods</h2>
60
+ <ul>
61
+
62
+ <li class="method">
63
+ <a href="DNSBL/Client.html#method-c-new">::new</a>
64
+ &mdash;
65
+ <span class="container">DNSBL::Client</span>
66
+
67
+ <li class="method">
68
+ <a href="DNSBL/Client.html#method-i-__phpot_decoder">#__phpot_decoder</a>
69
+ &mdash;
70
+ <span class="container">DNSBL::Client</span>
71
+
72
+ <li class="method">
73
+ <a href="DNSBL/Client.html#method-i-_decode_response">#_decode_response</a>
74
+ &mdash;
75
+ <span class="container">DNSBL::Client</span>
76
+
77
+ <li class="method">
78
+ <a href="DNSBL/Client.html#method-i-_encode_query">#_encode_query</a>
79
+ &mdash;
80
+ <span class="container">DNSBL::Client</span>
81
+
82
+ <li class="method">
83
+ <a href="DNSBL/Client.html#method-i-add_dnsbl">#add_dnsbl</a>
84
+ &mdash;
85
+ <span class="container">DNSBL::Client</span>
86
+
87
+ <li class="method">
88
+ <a href="DNSBL/Client.html#method-i-dnsbls">#dnsbls</a>
89
+ &mdash;
90
+ <span class="container">DNSBL::Client</span>
91
+
92
+ <li class="method">
93
+ <a href="DNSBL/Client.html#method-i-lookup">#lookup</a>
94
+ &mdash;
95
+ <span class="container">DNSBL::Client</span>
96
+
97
+ <li class="method">
98
+ <a href="Resolv/DNS/Config.html#method-i-nameservers">#nameservers</a>
99
+ &mdash;
100
+ <span class="container">Resolv::DNS::Config</span>
101
+
102
+ <li class="method">
103
+ <a href="DNSBL/Client.html#method-i-nameservers-3D">#nameservers=</a>
104
+ &mdash;
105
+ <span class="container">DNSBL::Client</span>
106
+
107
+ <li class="method">
108
+ <a href="DNSBL/Client.html#method-i-normalize">#normalize</a>
109
+ &mdash;
110
+ <span class="container">DNSBL::Client</span>
111
+ </ul>
112
+ </main>
113
+
114
+
115
+ <footer id="validator-badges" role="contentinfo">
116
+ <p><a href="http://validator.w3.org/check/referer">Validate</a>
117
+ <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
118
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
119
+ </footer>
120
+
data/lib/dnsbl/client.rb CHANGED
@@ -6,7 +6,9 @@ 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
13
  return @nameservers if @namservers
12
14
 
@@ -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.1"
3
+ # Current version of the dnsbl-client gem
4
+ VERSION = "1.0.2"
4
5
  end
5
6
  end
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,6 +56,55 @@ files:
56
56
  - data/three-level-tlds
57
57
  - data/two-level-tlds
58
58
  - dnsbl-client.gemspec
59
+ - html/DNSBL.html
60
+ - html/DNSBL/Client.html
61
+ - html/DNSBL/DNSBLResult.html
62
+ - html/README_md.html
63
+ - html/Resolv.html
64
+ - html/Resolv/DNS.html
65
+ - html/Resolv/DNS/Config.html
66
+ - html/created.rid
67
+ - html/fonts.css
68
+ - html/fonts/Lato-Light.ttf
69
+ - html/fonts/Lato-LightItalic.ttf
70
+ - html/fonts/Lato-Regular.ttf
71
+ - html/fonts/Lato-RegularItalic.ttf
72
+ - html/fonts/SourceCodePro-Bold.ttf
73
+ - html/fonts/SourceCodePro-Regular.ttf
74
+ - html/images/add.png
75
+ - html/images/arrow_up.png
76
+ - html/images/brick.png
77
+ - html/images/brick_link.png
78
+ - html/images/bug.png
79
+ - html/images/bullet_black.png
80
+ - html/images/bullet_toggle_minus.png
81
+ - html/images/bullet_toggle_plus.png
82
+ - html/images/date.png
83
+ - html/images/delete.png
84
+ - html/images/find.png
85
+ - html/images/loadingAnimation.gif
86
+ - html/images/macFFBgHack.png
87
+ - html/images/package.png
88
+ - html/images/page_green.png
89
+ - html/images/page_white_text.png
90
+ - html/images/page_white_width.png
91
+ - html/images/plugin.png
92
+ - html/images/ruby.png
93
+ - html/images/tag_blue.png
94
+ - html/images/tag_green.png
95
+ - html/images/transparent.png
96
+ - html/images/wrench.png
97
+ - html/images/wrench_orange.png
98
+ - html/images/zoom.png
99
+ - html/index.html
100
+ - html/js/darkfish.js
101
+ - html/js/jquery.js
102
+ - html/js/navigation.js
103
+ - html/js/search.js
104
+ - html/js/search_index.js
105
+ - html/js/searcher.js
106
+ - html/rdoc.css
107
+ - html/table_of_contents.html
59
108
  - lib/dnsbl/client.rb
60
109
  - lib/dnsbl/client/version.rb
61
110
  - test/helper.rb