net-dns 0.8.0 → 0.20.0

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 +6 -14
  2. data/.rspec +1 -0
  3. data/.travis.yml +9 -16
  4. data/CHANGELOG.md +37 -13
  5. data/LICENSE.txt +56 -0
  6. data/README.md +94 -77
  7. data/demo/check_soa.rb +27 -38
  8. data/demo/threads.rb +3 -7
  9. data/lib/net/dns/header.rb +86 -110
  10. data/lib/net/dns/names.rb +31 -31
  11. data/lib/net/dns/packet.rb +148 -158
  12. data/lib/net/dns/question.rb +41 -42
  13. data/lib/net/dns/resolver/socks.rb +47 -55
  14. data/lib/net/dns/resolver/timeouts.rb +19 -30
  15. data/lib/net/dns/resolver.rb +151 -176
  16. data/lib/net/dns/rr/a.rb +45 -55
  17. data/lib/net/dns/rr/aaaa.rb +39 -50
  18. data/lib/net/dns/rr/classes.rb +32 -37
  19. data/lib/net/dns/rr/cname.rb +31 -41
  20. data/lib/net/dns/rr/hinfo.rb +40 -56
  21. data/lib/net/dns/rr/mr.rb +31 -42
  22. data/lib/net/dns/rr/mx.rb +35 -47
  23. data/lib/net/dns/rr/ns.rb +31 -41
  24. data/lib/net/dns/rr/null.rb +10 -15
  25. data/lib/net/dns/rr/ptr.rb +16 -24
  26. data/lib/net/dns/rr/soa.rb +36 -35
  27. data/lib/net/dns/rr/srv.rb +18 -19
  28. data/lib/net/dns/rr/txt.rb +11 -16
  29. data/lib/net/dns/rr/types.rb +118 -109
  30. data/lib/net/dns/rr.rb +107 -117
  31. data/lib/net/dns/version.rb +5 -13
  32. data/lib/net/dns.rb +6 -11
  33. metadata +18 -83
  34. data/.gitignore +0 -8
  35. data/Gemfile +0 -4
  36. data/Rakefile +0 -71
  37. data/fixtures/resolv.conf +0 -4
  38. data/lib/net/dns/core_ext.rb +0 -52
  39. data/net-dns.gemspec +0 -35
  40. data/test/header_test.rb +0 -167
  41. data/test/names_test.rb +0 -21
  42. data/test/packet_test.rb +0 -49
  43. data/test/question_test.rb +0 -83
  44. data/test/resolver/timeouts_test.rb +0 -109
  45. data/test/resolver_test.rb +0 -117
  46. data/test/rr/a_test.rb +0 -113
  47. data/test/rr/aaaa_test.rb +0 -109
  48. data/test/rr/classes_test.rb +0 -85
  49. data/test/rr/cname_test.rb +0 -97
  50. data/test/rr/hinfo_test.rb +0 -117
  51. data/test/rr/mr_test.rb +0 -105
  52. data/test/rr/mx_test.rb +0 -112
  53. data/test/rr/ns_test.rb +0 -86
  54. data/test/rr/types_test.rb +0 -69
  55. data/test/rr_test.rb +0 -131
  56. data/test/test_helper.rb +0 -4
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODAwMGQ4ODMyYTIyZmNkN2NlNjIwMDk3Y2Y0ODNmYmZkODY0NmE4NQ==
5
- data.tar.gz: !binary |-
6
- NTAzODI5MjhmZWNmZDZmOWEyM2UyMDBkZDRmNmQxY2E4MDE0YjYxYw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzMzY2RhYjJlNTcyNTllMzQ4ODdlYjkzNjViY2QyNDg4ZTQxNDJhNjA0MDM1
10
- OThjMGZjY2EwMmY2ZTNjYTM0NGRmMDM2YzcwMDk0Yzg2MGVjYzNiODYzZDhj
11
- M2JjNzExN2FkMTdlMzg5MGE1ZWIyMWJlOTQzMTBmMzYxOTAwYjk=
12
- data.tar.gz: !binary |-
13
- NDRiZjIyY2UxZTMxMjYxZDM3MjhlYjFiNDAxNDhmNWEwMDRmODNiYjg3MmY3
14
- MzQxNWU4ZTlhMGE1ZDQ0MGYzNzBmMTU4YzVkYjc4ZjJlYmQ1NmY0OTE3ZDQ5
15
- ZjkwYTNiZmM5ODBlMjM1MWU0Y2I5MmU4ZmI4NWJmNmEzMzRiNTQ=
2
+ SHA256:
3
+ metadata.gz: fec69b4a6e824defa6fb7a25a020a67d0dba5340f2f42b1c489e3b73027b6577
4
+ data.tar.gz: bd9fcd575cb009fa14ce0443ea3b415f0924a04c3a63be620b350c913b93fe39
5
+ SHA512:
6
+ metadata.gz: 3ba5ecc052ddd89bfc5bb264ce0a11edb2aa791b1d6285075f0f96245634b1b73bb69e29e883bd4656a85d6c82e6f331e11cfb66b55a10da27b90221ad61f8d6
7
+ data.tar.gz: 0ff1b210ef56b91a7dc3d914039bedb7e08803c8838a0eefe1233fef4c97a7e817b06387e45bc6b77354a3efe7f9fc885499efff0aabacb07ac24c3eb75aca15
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml CHANGED
@@ -1,20 +1,13 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
7
- - 2.0.0
8
- # - jruby-18mode
9
- # - jruby-19mode
10
- - rbx-18mode
11
- # - ruby-head
12
- # - jruby-head
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - jruby-9.1.5.0
10
+ - ruby-head
13
11
 
14
- notifications:
15
- recipients:
16
- - weppos@weppos.net
17
-
18
- matrix:
19
- allow_failures:
20
- - rvm: 2.0.0
12
+ cache:
13
+ - bundler
data/CHANGELOG.md CHANGED
@@ -1,22 +1,46 @@
1
1
  # Changelog
2
2
 
3
3
 
4
- ## master
4
+ ## Release 0.20.0
5
5
 
6
- - FIXED: undefined local variable or method `source_address_inet6' (GH-40). [Thanks @simsicon]
6
+ - CHANGED: Minimum Ruby version is now 2.7
7
7
 
8
- - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). [Thanks @nicholasren]
8
+ - CHANGED: Merged changes from gitlab-net-dns @stanhu
9
9
 
10
- - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). [Thanks @ebroder]
10
+ - FIXED: Fixed undefined method 'size' errors (GH-46, GH-81) @stanhu
11
11
 
12
- - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). [Thanks @johnroa]
12
+ - FIXED: uninitialized constant Net::DNS::Resolver::TimeoutError (GH-82, GH-83, GH-84)
13
+
14
+ - ADDED: Added URI/SPF/CAA type code
15
+
16
+
17
+ ## Release 0.9.0
18
+
19
+ - CHANGED: Major code cleanup.
20
+
21
+ - CHANGED: Minimum Ruby version is now 2.1
22
+
23
+ - FIXED: Fixed CI run (GH-77).
24
+
25
+ - FIXED: Fixed deprecated references to Fixnum.
26
+
27
+
28
+ ## Release 0.8.0
29
+
30
+ - FIXED: undefined local variable or method `source_address_inet6' (GH-40). @simsicon
31
+
32
+ - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). @nicholasren
33
+
34
+ - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). @ebroder
35
+
36
+ - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). @johnroa
13
37
 
14
38
  - CHANGED: Removed setup.rb installation script.
15
39
 
16
40
 
17
41
  ## Release 0.7.1
18
42
 
19
- - FIXED: Invalid file permissions on several files (GH-35) [Thanks @jamespharaoh]
43
+ - FIXED: Invalid file permissions on several files (GH-35) @jamespharaoh
20
44
 
21
45
 
22
46
  ## Release 0.7.0
@@ -27,15 +51,15 @@
27
51
 
28
52
  - FIXED: Cleaned up require dependency and recursive require statements.
29
53
 
30
- - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) [Thanks @shadowbq, @eik3]
54
+ - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) @shadowbq, @eik3
31
55
 
32
- - FIXED: SRV record not required by Net::DNS::RR (GH-27) [Thanks @sebastian]
56
+ - FIXED: SRV record not required by Net::DNS::RR (GH-27) @sebastian
33
57
 
34
- - FIXED: Resolver now supports IPv6 (GH-32) [Thanks @jamesotron]
58
+ - FIXED: Resolver now supports IPv6 (GH-32) @jamesotron
35
59
 
36
- - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) [Thanks @dd23]
60
+ - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) @dd23
37
61
 
38
- - FIXED: Net::DNS::Question changes input arguments (GH-7) [Thanks @gfarfl]
62
+ - FIXED: Net::DNS::Question changes input arguments (GH-7) @gfarfl
39
63
 
40
64
  - CHANGED: Refactoring unit test to follow most used Ruby conventions.
41
65
 
@@ -56,9 +80,9 @@
56
80
 
57
81
  - ADDED: Net::DNS::Packet#to_s method (alias of #inspect)
58
82
 
59
- - FIXED: typo in lib/net/dns/rr/ptr.rb [Thanks Chris Lundquist]
83
+ - FIXED: typo in lib/net/dns/rr/ptr.rb. Thanks Chris Lundquist.
60
84
 
61
- - FIXED: warning: method redefined; discarding old inspect (GH-3) [Thanks Kevin Baker]
85
+ - FIXED: warning: method redefined; discarding old inspect (GH-3). Thanks Kevin Baker.
62
86
 
63
87
  - FIXED: issue with rescue ArgumentError (GH-5) and with IPAddr handling (GH-6)
64
88
 
data/LICENSE.txt ADDED
@@ -0,0 +1,56 @@
1
+ net-dns is copyrighted free software by Marco Ceresa (@bluemonk) and Simone Carletti (@weppos).
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/README.md CHANGED
@@ -12,16 +12,16 @@ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net
12
12
 
13
13
  ## Requirements
14
14
 
15
- * Ruby >= 1.8.7
15
+ Ruby >= 2.6
16
16
 
17
17
 
18
18
  ## Installation
19
19
 
20
20
  The best way to install this library is via [RubyGems](https://rubygems.org/).
21
21
 
22
- $ gem install net-dns
23
-
24
- You might need administrator privileges on your system to install the gem.
22
+ ```
23
+ gem install net-dns
24
+ ```
25
25
 
26
26
 
27
27
  ## API Documentation
@@ -33,71 +33,80 @@ Visit the page http://rdoc.info/gems/net-dns
33
33
 
34
34
  The simplest way to use the library is to invoke the Resolver() method:
35
35
 
36
- require 'rubygems'
37
- require 'net/dns'
38
- p Resolver("www.google.com")
36
+ ```ruby
37
+ require 'rubygems'
38
+ require 'net/dns'
39
+ p Resolver("www.google.com")
40
+ ```
39
41
 
40
42
  The output is compatible with BIND zone files and it's the same you would get with the dig utility.
41
43
 
42
- ;; Answer received from localhost:53 (212 bytes)
43
- ;;
44
- ;; HEADER SECTION
45
- ;; id = 64075
46
- ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
47
- ;; ra = 1 ad = 0 cd = 0 rcode = NoError
48
- ;; qdCount = 1 anCount = 3 nsCount = 4 arCount = 4
49
-
50
- ;; QUESTION SECTION (1 record):
51
- ;; google.com. IN A
52
-
53
- ;; ANSWER SECTION (3 records):
54
- google.com. 212 IN A 74.125.45.100
55
- google.com. 212 IN A 74.125.67.100
56
- google.com. 212 IN A 209.85.171.100
57
-
58
- ;; AUTHORITY SECTION (4 records):
59
- google.com. 345512 IN NS ns1.google.com.
60
- google.com. 345512 IN NS ns4.google.com.
61
- google.com. 345512 IN NS ns2.google.com.
62
- google.com. 345512 IN NS ns3.google.com.
63
-
64
- ;; ADDITIONAL SECTION (4 records):
65
- ns1.google.com. 170275 IN A 216.239.32.10
66
- ns2.google.com. 170275 IN A 216.239.34.10
67
- ns3.google.com. 170275 IN A 216.239.36.10
68
- ns4.google.com. 170275 IN A 216.239.38.10
44
+ ```
45
+ ;; Answer received from localhost:53 (212 bytes)
46
+ ;;
47
+ ;; HEADER SECTION
48
+ ;; id = 64075
49
+ ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
50
+ ;; ra = 1 ad = 0 cd = 0 rcode = NoError
51
+ ;; qdCount = 1 anCount = 3 nsCount = 4 arCount = 4
52
+
53
+ ;; QUESTION SECTION (1 record):
54
+ ;; google.com. IN A
55
+
56
+ ;; ANSWER SECTION (3 records):
57
+ google.com. 212 IN A 74.125.45.100
58
+ google.com. 212 IN A 74.125.67.100
59
+ google.com. 212 IN A 209.85.171.100
60
+
61
+ ;; AUTHORITY SECTION (4 records):
62
+ google.com. 345512 IN NS ns1.google.com.
63
+ google.com. 345512 IN NS ns4.google.com.
64
+ google.com. 345512 IN NS ns2.google.com.
65
+ google.com. 345512 IN NS ns3.google.com.
66
+
67
+ ;; ADDITIONAL SECTION (4 records):
68
+ ns1.google.com. 170275 IN A 216.239.32.10
69
+ ns2.google.com. 170275 IN A 216.239.34.10
70
+ ns3.google.com. 170275 IN A 216.239.36.10
71
+ ns4.google.com. 170275 IN A 216.239.38.10
72
+ ```
69
73
 
70
74
  An optional block can be passed yielding the Net::DNS::Packet object
71
75
 
72
- Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
73
- # => 484 bytes
76
+ ```ruby
77
+ Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
78
+ # => 484 bytes
79
+ ```
74
80
 
75
81
  Same for Net::DNS::Resolver.start():
76
82
 
77
- Net::DNS::Resolver.start("google.com").answer.size
78
- # => 5
83
+ ```ruby
84
+ Net::DNS::Resolver.start("google.com").answer.size
85
+ # => 5
86
+ ```
79
87
 
80
88
  As optional parameters, +TYPE+ and +CLASS+ can be specified.
81
89
 
82
- p Net::DNS::Resolver.start("google.com", Net::DNS::MX)
83
-
84
- ;; Answer received from localhost:53 (316 bytes)
85
- ;;
86
- ;; HEADER SECTION
87
- ;; id = 59980
88
- ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
89
- ;; ra = 1 ad = 0 cd = 0 rcode = NoError
90
- ;; qdCount = 1 anCount = 4 nsCount = 4 arCount = 8
91
-
92
- ;; QUESTION SECTION (1 record):
93
- ;; google.com. IN MX
94
-
95
- ;; ANSWER SECTION (4 records):
96
- google.com. 10800 IN MX 10 smtp2.google.com.
97
- google.com. 10800 IN MX 10 smtp3.google.com.
98
- google.com. 10800 IN MX 10 smtp4.google.com.
99
- google.com. 10800 IN MX 10 smtp1.google.com.
90
+ ```ruby
91
+ p Net::DNS::Resolver.start("google.com", Net::DNS::MX)
92
+
93
+ ;; Answer received from localhost:53 (316 bytes)
94
+ ;;
95
+ ;; HEADER SECTION
96
+ ;; id = 59980
97
+ ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
98
+ ;; ra = 1 ad = 0 cd = 0 rcode = NoError
99
+ ;; qdCount = 1 anCount = 4 nsCount = 4 arCount = 8
100
100
 
101
+ ;; QUESTION SECTION (1 record):
102
+ ;; google.com. IN MX
103
+
104
+ ;; ANSWER SECTION (4 records):
105
+ google.com. 10800 IN MX 10 smtp2.google.com.
106
+ google.com. 10800 IN MX 10 smtp3.google.com.
107
+ google.com. 10800 IN MX 10 smtp4.google.com.
108
+ google.com. 10800 IN MX 10 smtp1.google.com.
109
+ ```
101
110
 
102
111
  ## Handling the response packet
103
112
 
@@ -113,35 +122,43 @@ A DNS packet is divided into 5 sections:
113
122
 
114
123
  You can access each section by calling the attribute with the same name on a Packet object:
115
124
 
116
- packet = Net::DNS::Resolver.start("google.com")
117
-
118
- header = packet.header
119
- answer = packet.answer
120
-
121
- puts "The packet is #{packet.data.size} bytes"
122
- puts "It contains #{header.anCount} answer entries"
123
-
124
- answer.any? {|ans| p ans}
125
-
125
+ ```ruby
126
+ packet = Net::DNS::Resolver.start("google.com")
127
+
128
+ header = packet.header
129
+ answer = packet.answer
130
+
131
+ puts "The packet is #{packet.data.size} bytes"
132
+ puts "It contains #{header.anCount} answer entries"
133
+
134
+ answer.any? {|ans| p ans}
135
+ ```
136
+
126
137
  The output is
127
138
 
128
- The packet is 378 bytes
129
- It contains 3 answer entries
130
- google.com. 244 IN A 74.125.45.100
131
- google.com. 244 IN A 74.125.67.100
132
- google.com. 244 IN A 209.85.171.100
139
+ ```
140
+ The packet is 378 bytes
141
+ It contains 3 answer entries
142
+ google.com. 244 IN A 74.125.45.100
143
+ google.com. 244 IN A 74.125.67.100
144
+ google.com. 244 IN A 209.85.171.100
145
+ ```
133
146
 
134
147
  A better way to handle the answer section is to use the iterators directly on a Packet object:
135
148
 
136
- packet.each_address do |ip|
137
- puts "#{ip} is alive" if Ping.pingecho(ip.to_s, 10, 80)
138
- end
149
+ ```ruby
150
+ packet.each_address do |ip|
151
+ puts "#{ip} is alive" if Ping.pingecho(ip.to_s, 10, 80)
152
+ end
153
+ ```
139
154
 
140
155
  Gives:
141
156
 
142
- 74.125.45.100 is alive
143
- 74.125.67.100 is alive
144
- 209.85.171.100 is alive
157
+ ```
158
+ 74.125.45.100 is alive
159
+ 74.125.67.100 is alive
160
+ 209.85.171.100 is alive
161
+ ```
145
162
 
146
163
 
147
164
  ## License
data/demo/check_soa.rb CHANGED
@@ -1,9 +1,8 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems' if "#{RUBY_VERSION}" < "1.9.0"
3
+ require 'rubygems' if RUBY_VERSION.to_s < "1.9.0"
4
4
  require 'net/dns'
5
5
 
6
-
7
6
  #------------------------------------------------------------------------------
8
7
  # Get the domain from the command line.
9
8
  #------------------------------------------------------------------------------
@@ -16,100 +15,90 @@ domain = ARGV[0]
16
15
  # Find all the nameservers for the domain.
17
16
  #------------------------------------------------------------------------------
18
17
 
19
- res = Net::DNS::Resolver.new(:defname => false, :retry => 2)
18
+ res = Net::DNS::Resolver.new(defname: false, retry: 2)
20
19
 
21
20
  ns_req = res.query(domain, Net::DNS::NS)
22
- unless ns_req and ns_req.header.anCount > 0
21
+ unless ns_req && (ns_req.header.anCount > 0)
23
22
  raise ArgumentError, "No nameservers found for domain: #{res.errorstring}"
24
23
  end
25
24
 
26
-
27
25
  # Send out non-recursive queries
28
26
  res.recurse = false
29
27
  # Do not buffer standard out
30
- #| = 1;
31
-
28
+ # | = 1;
32
29
 
33
30
  #------------------------------------------------------------------------------
34
31
  # Check the SOA record on each nameserver.
35
32
  #------------------------------------------------------------------------------
36
33
 
37
34
  ns_req.each_nameserver do |ns|
38
-
39
35
  #----------------------------------------------------------------------
40
36
  # Set the resolver to query this nameserver.
41
37
  #----------------------------------------------------------------------
42
-
38
+
43
39
  # In order to lookup the IP(s) of the nameserver, we need a Resolver
44
40
  # object that is set to our local, recursive nameserver. So we create
45
41
  # a new object just to do that.
46
-
42
+
47
43
  local_res = Net::DNS::Resolver.new
48
-
44
+
49
45
  a_req = local_res.query(ns, Net::DNS::A)
50
-
51
-
52
- unless a_req
46
+
47
+ unless a_req
53
48
  puts "Can not find address for ns: " + res.errorstring + "\n"
54
49
  next
55
50
  end
56
-
57
-
58
- a_req.each_address do |ip|
59
51
 
52
+ a_req.each_address do |ip|
60
53
  #----------------------------------------------------------------------
61
54
  # Ask this IP.
62
55
  #----------------------------------------------------------------------
63
- res.nameservers=ip
64
-
56
+ res.nameservers = ip
57
+
65
58
  print "#{ns} (#{ip}): "
66
-
59
+
67
60
  #----------------------------------------------------------------------
68
61
  # Get the SOA record.
69
62
  #----------------------------------------------------------------------
70
-
63
+
71
64
  soa_req = res.send(domain, Net::DNS::SOA, Net::DNS::IN)
72
-
73
- if soa_req == nil
65
+
66
+ if soa_req.nil?
74
67
  puts res.errorstring, "\n"
75
68
  next
76
69
  end
77
-
70
+
78
71
  #----------------------------------------------------------------------
79
72
  # Is this nameserver authoritative for the domain?
80
73
  #----------------------------------------------------------------------
81
-
82
- unless soa_req.header.auth?
74
+
75
+ unless soa_req.header.auth?
83
76
  print "isn't authoritative for domain\n"
84
77
  next
85
78
  end
86
-
79
+
87
80
  #----------------------------------------------------------------------
88
81
  # We should have received exactly one answer.
89
82
  #----------------------------------------------------------------------
90
-
91
- unless soa_req.header.anCount == 1
83
+
84
+ unless soa_req.header.anCount == 1
92
85
  print "expected 1 answer, got " + soa_req.header.anCount.to_s + "\n"
93
86
  next
94
87
  end
95
-
88
+
96
89
  #----------------------------------------------------------------------
97
90
  # Did we receive an SOA record?
98
91
  #----------------------------------------------------------------------
99
-
92
+
100
93
  unless soa_req.answer[0].class == Net::DNS::RR::SOA
101
94
  print "expected SOA, got " + Net::DNS::RR::RRTypes.to_str(soa_req.answer[0].type) + "\n"
102
95
  next
103
96
  end
104
-
97
+
105
98
  #----------------------------------------------------------------------
106
99
  # Print the serial number.
107
100
  #----------------------------------------------------------------------
108
-
101
+
109
102
  print "has serial number " + soa_req.answer[0].serial.to_s + "\n"
110
-
111
103
  end
112
104
  end
113
-
114
-
115
-
data/demo/threads.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'rubygems' if "#{RUBY_VERSION}" < "1.9.0"
1
+ require 'rubygems' if RUBY_VERSION.to_s < "1.9.0"
2
2
  require 'net/dns'
3
3
 
4
4
  a = ["ibm.com", "sun.com", "redhat.com"]
5
5
 
6
6
  threads = []
7
7
 
8
- for dom in a
8
+ a.each do |dom|
9
9
  threads << Thread.new(dom) do |domain|
10
10
  res = Net::DNS::Resolver.new
11
11
  res.query(domain, Net::DNS::NS).each_nameserver do |ns|
@@ -15,8 +15,4 @@ for dom in a
15
15
  end
16
16
  end
17
17
 
18
- threads.each do |t|
19
- t.join
20
- end
21
-
22
-
18
+ threads.each(&:join)