net-dns2 0.8.1

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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +20 -0
  4. data/CHANGELOG.md +105 -0
  5. data/Gemfile +4 -0
  6. data/README.md +155 -0
  7. data/Rakefile +94 -0
  8. data/THANKS.rdoc +24 -0
  9. data/demo/check_soa.rb +115 -0
  10. data/demo/threads.rb +22 -0
  11. data/lib/net/dns.rb +112 -0
  12. data/lib/net/dns/core_ext.rb +52 -0
  13. data/lib/net/dns/header.rb +713 -0
  14. data/lib/net/dns/names.rb +118 -0
  15. data/lib/net/dns/packet.rb +563 -0
  16. data/lib/net/dns/question.rb +188 -0
  17. data/lib/net/dns/resolver.rb +1313 -0
  18. data/lib/net/dns/resolver/socks.rb +154 -0
  19. data/lib/net/dns/resolver/timeouts.rb +75 -0
  20. data/lib/net/dns/rr.rb +366 -0
  21. data/lib/net/dns/rr/a.rb +124 -0
  22. data/lib/net/dns/rr/aaaa.rb +103 -0
  23. data/lib/net/dns/rr/classes.rb +133 -0
  24. data/lib/net/dns/rr/cname.rb +82 -0
  25. data/lib/net/dns/rr/hinfo.rb +108 -0
  26. data/lib/net/dns/rr/mr.rb +79 -0
  27. data/lib/net/dns/rr/mx.rb +92 -0
  28. data/lib/net/dns/rr/ns.rb +78 -0
  29. data/lib/net/dns/rr/null.rb +53 -0
  30. data/lib/net/dns/rr/ptr.rb +83 -0
  31. data/lib/net/dns/rr/soa.rb +78 -0
  32. data/lib/net/dns/rr/srv.rb +45 -0
  33. data/lib/net/dns/rr/txt.rb +61 -0
  34. data/lib/net/dns/rr/types.rb +193 -0
  35. data/lib/net/dns/version.rb +16 -0
  36. data/net-dns.gemspec +37 -0
  37. data/test/header_test.rb +167 -0
  38. data/test/names_test.rb +21 -0
  39. data/test/packet_test.rb +49 -0
  40. data/test/question_test.rb +83 -0
  41. data/test/resolver_test.rb +117 -0
  42. data/test/rr/a_test.rb +113 -0
  43. data/test/rr/aaaa_test.rb +109 -0
  44. data/test/rr/classes_test.rb +85 -0
  45. data/test/rr/cname_test.rb +97 -0
  46. data/test/rr/hinfo_test.rb +117 -0
  47. data/test/rr/mr_test.rb +105 -0
  48. data/test/rr/mx_test.rb +112 -0
  49. data/test/rr/ns_test.rb +86 -0
  50. data/test/rr/types_test.rb +69 -0
  51. data/test/rr_test.rb +131 -0
  52. data/test/test_helper.rb +4 -0
  53. metadata +158 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55bf79bac06ca433152dd87367a15b48478a79ea
4
+ data.tar.gz: 573df60f08c57700bb4a92b70b249233c835ebf1
5
+ SHA512:
6
+ metadata.gz: 214b72d842cd77143078d03fe9c2405e5e87f4f119f0f5858a7b94263e0a6bfbd6fec54ab60eee93744a3ad2b6c1c47b3fb099ca366f6d94e67ee5f3cf4710f1
7
+ data.tar.gz: 9a9d7c9aa8972344907d4f92abcae0694fa16e2ee8ffee2f8e1d8b8f87445109a256ea22af74f643ecb23793bd09f8e6b2b38be29f8c247509b723b040877bc6
@@ -0,0 +1,8 @@
1
+ # Bundler
2
+ .bundle
3
+ pkg/*
4
+ Gemfile.lock
5
+
6
+ # YARD
7
+ .yardoc
8
+ yardoc/
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+
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
13
+
14
+ notifications:
15
+ recipients:
16
+ - weppos@weppos.net
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: 2.0.0
@@ -0,0 +1,105 @@
1
+ # Changelog
2
+
3
+ ## Release 0.8.1
4
+ - First release from fork by Christopher Carpenter(mordocai@mordocai.net)
5
+ - FIXED: Multiple bugs with Resolver::source_address= preventing it from
6
+ executing.
7
+ - FIXED: Implemented send_raw_tcp and send_raw_udp
8
+ - CHANGED: Added interface config parameter for Net::DNS::Resolver,
9
+ currently only used by send_raw*
10
+ - CHANGED: Added TODO file for known things that I need to do.
11
+
12
+ ## Release 0.8.0
13
+
14
+ - FIXED: undefined local variable or method `source_address_inet6' (GH-40). [Thanks @simsicon]
15
+
16
+ - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). [Thanks @nicholasren]
17
+
18
+ - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). [Thanks @ebroder]
19
+
20
+ - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). [Thanks @johnroa]
21
+
22
+ - CHANGED: Removed setup.rb installation script.
23
+
24
+
25
+ ## Release 0.7.1
26
+
27
+ - FIXED: Invalid file permissions on several files (GH-35) [Thanks @jamespharaoh]
28
+
29
+
30
+ ## Release 0.7.0
31
+
32
+ - ADDED: Added (experimental) Support for HINFO record.
33
+
34
+ - FIXED: Use Net::DNS::Resolver::Error class (not ResolverError, which does not exist).
35
+
36
+ - FIXED: Cleaned up require dependency and recursive require statements.
37
+
38
+ - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) [Thanks @shadowbq, @eik3]
39
+
40
+ - FIXED: SRV record not required by Net::DNS::RR (GH-27) [Thanks @sebastian]
41
+
42
+ - FIXED: Resolver now supports IPv6 (GH-32) [Thanks @jamesotron]
43
+
44
+ - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) [Thanks @dd23]
45
+
46
+ - FIXED: Net::DNS::Question changes input arguments (GH-7) [Thanks @gfarfl]
47
+
48
+ - CHANGED: Refactoring unit test to follow most used Ruby conventions.
49
+
50
+ - CHANGED: Rewritten and simplified Net::DNS::Classes. Improved test harness.
51
+
52
+ - CHANGED: Removed Jeweler development dependency.
53
+
54
+ - CHANGED: The library is now compatible with Bundler.
55
+
56
+ - CHANGED: Minimum supported Ruby version changed to Ruby 1.8.7.
57
+
58
+ - CHANGED: Rescue NameError so unsupported record types only result in a warning.
59
+
60
+ - CHANGED: Renamed Net::DNS::Resolver#send to Net::DNS::Resolver#query to avoid overriding default meaning of send method.
61
+
62
+
63
+ ## Release 0.6.1
64
+
65
+ - ADDED: Net::DNS::Packet#to_s method (alias of #inspect)
66
+
67
+ - FIXED: typo in lib/net/dns/rr/ptr.rb [Thanks Chris Lundquist]
68
+
69
+ - FIXED: warning: method redefined; discarding old inspect (GH-3) [Thanks Kevin Baker]
70
+
71
+ - FIXED: issue with rescue ArgumentError (GH-5) and with IPAddr handling (GH-6)
72
+
73
+
74
+ ## Release 0.6.0
75
+
76
+ *WARNING:- If you are upgrading from a previous minor release, check out the Compatibility issue list below.
77
+
78
+ - FIXED: Added missing #to_s method to Net::DNS::Question.
79
+
80
+ - FIXED: Compatibility with Ruby 1.9
81
+
82
+ - FIXED: Types regexp order issue
83
+
84
+ - CHANGED: Refactoring unit test to follow most used Ruby conventions
85
+
86
+ - CHANGED: default timeout is now 5 seconds for both UDP and TCP
87
+
88
+ - CHANGED: Moved main dns.rb file to lib/net folder as default for GEMs. In this way it can be autoloaded when the gem is required.
89
+
90
+ ### Compatibility issues
91
+
92
+ - CHANGED: RR#set_stype scope is now private to prevent invalid usage.
93
+
94
+ - CHANGED: DnsTimeout#timeout now raises LocalJumpError instead of DnsTimeoutArgumentError when block is missing.
95
+
96
+ - CHANGED: Renamed Net::DNS::RR::Types::Types to Net::DNS::RR::Types::TYPES to follow Ruby coding standards.
97
+
98
+
99
+ ## Release 0.4
100
+
101
+ - many bug fixes (thanks guys!)
102
+ - a whole new class Net::DNS::Header::RCode
103
+ - new methods in Net::DNS::Resolver class to do AXFR queries
104
+ - a new SRV resource record written by Dan Janowski
105
+ - more documentation written and corrected
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in whois.gemspec
4
+ gemspec
@@ -0,0 +1,155 @@
1
+ # Net::DNS
2
+
3
+ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net::DNS module, but it evolved in time into a full Ruby library.
4
+
5
+
6
+ ## Features
7
+
8
+ - Complete OO interface
9
+ - Clean and intuitive API
10
+ - Modular and flexible
11
+
12
+
13
+ ## Requirements
14
+
15
+ * Ruby >= 1.8.7
16
+
17
+
18
+ ## Installation
19
+
20
+ The best way to install this library is via [RubyGems](https://rubygems.org/).
21
+
22
+ $ gem install net-dns
23
+
24
+ You might need administrator privileges on your system to install the gem.
25
+
26
+
27
+ ## API Documentation
28
+
29
+ Visit the page http://rdoc.info/gems/net-dns
30
+
31
+
32
+ ## Trivial resolver
33
+
34
+ The simplest way to use the library is to invoke the Resolver() method:
35
+
36
+ require 'rubygems'
37
+ require 'net/dns'
38
+ p Resolver("www.google.com")
39
+
40
+ The output is compatible with BIND zone files and it's the same you would get with the dig utility.
41
+
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
69
+
70
+ An optional block can be passed yielding the Net::DNS::Packet object
71
+
72
+ Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
73
+ # => 484 bytes
74
+
75
+ Same for Net::DNS::Resolver.start():
76
+
77
+ Net::DNS::Resolver.start("google.com").answer.size
78
+ # => 5
79
+
80
+ As optional parameters, +TYPE+ and +CLASS+ can be specified.
81
+
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.
100
+
101
+
102
+ ## Handling the response packet
103
+
104
+ The method Net::DNS::Resolver.start is a wrapper around Resolver.new. It returns a new Net::DNS::Packet object.
105
+
106
+ A DNS packet is divided into 5 sections:
107
+
108
+ - header section # => a Net::DNS::Header object
109
+ - question section # => a Net::DNS::Question object
110
+ - answer section # => an Array of Net::DNS::RR objects
111
+ - authority section # => an Array of Net::DNS::RR objects
112
+ - additional section # => an Array of Net::DNS::RR objects
113
+
114
+ You can access each section by calling the attribute with the same name on a Packet object:
115
+
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
+
126
+ The output is
127
+
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
133
+
134
+ A better way to handle the answer section is to use the iterators directly on a Packet object:
135
+
136
+ packet.each_address do |ip|
137
+ puts "#{ip} is alive" if Ping.pingecho(ip.to_s, 10, 80)
138
+ end
139
+
140
+ Gives:
141
+
142
+ 74.125.45.100 is alive
143
+ 74.125.67.100 is alive
144
+ 209.85.171.100 is alive
145
+
146
+
147
+ ## License
148
+
149
+ See License
150
+
151
+ ## Authors
152
+
153
+ - Marco Ceresa (@bluemonk)
154
+ - Simone Carletti (@weppos)
155
+ - Christopher Carpenter (@mordocai)
@@ -0,0 +1,94 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/lib')
5
+ require 'net/dns'
6
+
7
+
8
+ # Common package properties
9
+ PKG_NAME = ENV['PKG_NAME'] || 'net-dns'
10
+ PKG_VERSION = ENV['PKG_VERSION'] || Net::DNS::VERSION
11
+
12
+
13
+ # Run test by default.
14
+ task :default => [:test, :spec]
15
+
16
+
17
+ spec = Gem::Specification.new do |s|
18
+ s.name = PKG_NAME
19
+ s.version = PKG_VERSION
20
+ s.summary = "Pure Ruby DNS library."
21
+ s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
22
+
23
+ s.required_ruby_version = ">= 1.8.7"
24
+
25
+ s.authors = ["Marco Ceresa", "Simone Carletti"]
26
+ s.email = ["ceresa@gmail.com", "weppos@weppos.net"]
27
+ s.homepage = "http://github.com/bluemonk/net-dns"
28
+ s.rubyforge_project = "net-dns"
29
+
30
+ s.add_development_dependency "rake"
31
+ s.add_development_dependency "rspec"
32
+ s.add_development_dependency "yard"
33
+
34
+ s.files = `git ls-files`.split("\n")
35
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
+ s.require_paths = %w( lib )
37
+ end
38
+
39
+
40
+ require 'rubygems/package_task'
41
+
42
+ Gem::PackageTask.new(spec) do |pkg|
43
+ pkg.gem_spec = spec
44
+ end
45
+
46
+ desc "Build the gemspec file #{spec.name}.gemspec"
47
+ task :gemspec do
48
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
49
+ File.open(file, "w") {|f| f << spec.to_ruby }
50
+ end
51
+
52
+
53
+ require 'rake/testtask'
54
+
55
+ # Run all the tests in the /test folder
56
+ Rake::TestTask.new do |t|
57
+ t.libs << "test"
58
+ t.test_files = FileList["test/**/*_test.rb"]
59
+ t.verbose = true
60
+ end
61
+
62
+
63
+ require 'rspec/core/rake_task'
64
+ begin
65
+ require 'fuubar'
66
+ rescue LoadError
67
+ end
68
+
69
+ RSpec::Core::RakeTask.new do |t|
70
+ t.verbose = !!ENV["VERBOSE"]
71
+ t.rspec_opts = []
72
+ t.rspec_opts << ['--format', 'Fuubar'] if defined?(Fuubar)
73
+ end
74
+
75
+
76
+ require 'yard'
77
+
78
+ YARD::Rake::YardocTask.new(:yardoc) do |y|
79
+ y.options = ["--output-dir", "yardoc"]
80
+ end
81
+
82
+ namespace :yardoc do
83
+ task :clobber do
84
+ rm_r "yardoc" rescue nil
85
+ end
86
+ end
87
+
88
+ task :clobber => "yardoc:clobber"
89
+
90
+
91
+ desc "Open an irb session preloaded with this library"
92
+ task :console do
93
+ sh "irb -rubygems -I lib -r net/dns.rb"
94
+ end
@@ -0,0 +1,24 @@
1
+ Many thanks to these wonderful people:
2
+
3
+ - Paul Barry for his excellent article on May07 issue of LinuxJournal, for the kind words and for bug reports
4
+ - Dan Janowski (and his SRV RR)
5
+ - Joshua Abraham
6
+ - Ben April
7
+ - Gene Rogers
8
+ - Nicholas Veeser
9
+ - Gildas Cherruel
10
+ - Alex Dalitz
11
+ - Cory Wright
12
+ - Nicolas Pugnant
13
+ - Andrea Peltrin
14
+ - Giovanni Corriga
15
+ - Luca Russo
16
+ - Pierguido Lambri
17
+ - Andrea Pampuri
18
+ - _koo_
19
+ - Oyku Gencay
20
+ - Eric Liedtke
21
+ - Justin Mercier
22
+ - Daniel Berger
23
+ and all #ruby-lang people
24
+
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' if "#{RUBY_VERSION}" < "1.9.0"
4
+ require 'net/dns'
5
+
6
+
7
+ #------------------------------------------------------------------------------
8
+ # Get the domain from the command line.
9
+ #------------------------------------------------------------------------------
10
+
11
+ raise ArgumentError, "Usage: check_soa.rb domain\n" unless ARGV.size == 1
12
+
13
+ domain = ARGV[0]
14
+
15
+ #------------------------------------------------------------------------------
16
+ # Find all the nameservers for the domain.
17
+ #------------------------------------------------------------------------------
18
+
19
+ res = Net::DNS::Resolver.new(:defname => false, :retry => 2)
20
+
21
+ ns_req = res.query(domain, Net::DNS::NS)
22
+ unless ns_req and ns_req.header.anCount > 0
23
+ raise ArgumentError, "No nameservers found for domain: #{res.errorstring}"
24
+ end
25
+
26
+
27
+ # Send out non-recursive queries
28
+ res.recurse = false
29
+ # Do not buffer standard out
30
+ #| = 1;
31
+
32
+
33
+ #------------------------------------------------------------------------------
34
+ # Check the SOA record on each nameserver.
35
+ #------------------------------------------------------------------------------
36
+
37
+ ns_req.each_nameserver do |ns|
38
+
39
+ #----------------------------------------------------------------------
40
+ # Set the resolver to query this nameserver.
41
+ #----------------------------------------------------------------------
42
+
43
+ # In order to lookup the IP(s) of the nameserver, we need a Resolver
44
+ # object that is set to our local, recursive nameserver. So we create
45
+ # a new object just to do that.
46
+
47
+ local_res = Net::DNS::Resolver.new
48
+
49
+ a_req = local_res.query(ns, Net::DNS::A)
50
+
51
+
52
+ unless a_req
53
+ puts "Can not find address for ns: " + res.errorstring + "\n"
54
+ next
55
+ end
56
+
57
+
58
+ a_req.each_address do |ip|
59
+
60
+ #----------------------------------------------------------------------
61
+ # Ask this IP.
62
+ #----------------------------------------------------------------------
63
+ res.nameservers=ip
64
+
65
+ print "#{ns} (#{ip}): "
66
+
67
+ #----------------------------------------------------------------------
68
+ # Get the SOA record.
69
+ #----------------------------------------------------------------------
70
+
71
+ soa_req = res.send(domain, Net::DNS::SOA, Net::DNS::IN)
72
+
73
+ if soa_req == nil
74
+ puts res.errorstring, "\n"
75
+ next
76
+ end
77
+
78
+ #----------------------------------------------------------------------
79
+ # Is this nameserver authoritative for the domain?
80
+ #----------------------------------------------------------------------
81
+
82
+ unless soa_req.header.auth?
83
+ print "isn't authoritative for domain\n"
84
+ next
85
+ end
86
+
87
+ #----------------------------------------------------------------------
88
+ # We should have received exactly one answer.
89
+ #----------------------------------------------------------------------
90
+
91
+ unless soa_req.header.anCount == 1
92
+ print "expected 1 answer, got " + soa_req.header.anCount.to_s + "\n"
93
+ next
94
+ end
95
+
96
+ #----------------------------------------------------------------------
97
+ # Did we receive an SOA record?
98
+ #----------------------------------------------------------------------
99
+
100
+ unless soa_req.answer[0].class == Net::DNS::RR::SOA
101
+ print "expected SOA, got " + Net::DNS::RR::RRTypes.to_str(soa_req.answer[0].type) + "\n"
102
+ next
103
+ end
104
+
105
+ #----------------------------------------------------------------------
106
+ # Print the serial number.
107
+ #----------------------------------------------------------------------
108
+
109
+ print "has serial number " + soa_req.answer[0].serial.to_s + "\n"
110
+
111
+ end
112
+ end
113
+
114
+
115
+