gitlab-net-dns 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitlab-ci.yml +20 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +3 -0
  6. data/.rubocop_defaults.yml +359 -0
  7. data/.rubocop_todo.yml +207 -0
  8. data/.travis.yml +13 -0
  9. data/CHANGELOG.md +113 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE.txt +56 -0
  12. data/README.md +172 -0
  13. data/Rakefile +38 -0
  14. data/THANKS.rdoc +24 -0
  15. data/bin/console +14 -0
  16. data/demo/check_soa.rb +104 -0
  17. data/demo/threads.rb +18 -0
  18. data/gitlab-net-dns.gemspec +24 -0
  19. data/lib/net/dns.rb +104 -0
  20. data/lib/net/dns/header.rb +705 -0
  21. data/lib/net/dns/names.rb +120 -0
  22. data/lib/net/dns/packet.rb +560 -0
  23. data/lib/net/dns/question.rb +185 -0
  24. data/lib/net/dns/resolver.rb +1214 -0
  25. data/lib/net/dns/resolver/socks.rb +148 -0
  26. data/lib/net/dns/resolver/timeouts.rb +70 -0
  27. data/lib/net/dns/rr.rb +356 -0
  28. data/lib/net/dns/rr/a.rb +114 -0
  29. data/lib/net/dns/rr/aaaa.rb +94 -0
  30. data/lib/net/dns/rr/classes.rb +130 -0
  31. data/lib/net/dns/rr/cname.rb +74 -0
  32. data/lib/net/dns/rr/hinfo.rb +96 -0
  33. data/lib/net/dns/rr/mr.rb +70 -0
  34. data/lib/net/dns/rr/mx.rb +82 -0
  35. data/lib/net/dns/rr/ns.rb +70 -0
  36. data/lib/net/dns/rr/null.rb +50 -0
  37. data/lib/net/dns/rr/ptr.rb +77 -0
  38. data/lib/net/dns/rr/soa.rb +75 -0
  39. data/lib/net/dns/rr/srv.rb +41 -0
  40. data/lib/net/dns/rr/txt.rb +58 -0
  41. data/lib/net/dns/rr/types.rb +191 -0
  42. data/lib/net/dns/version.rb +8 -0
  43. data/spec/fixtures/resolv.conf +4 -0
  44. data/spec/spec_helper.rb +14 -0
  45. data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
  46. data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
  47. data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
  48. data/test/test_helper.rb +13 -0
  49. data/test/unit/header_test.rb +164 -0
  50. data/test/unit/names_test.rb +21 -0
  51. data/test/unit/packet_test.rb +47 -0
  52. data/test/unit/question_test.rb +81 -0
  53. data/test/unit/resolver_test.rb +114 -0
  54. data/test/unit/rr/a_test.rb +106 -0
  55. data/test/unit/rr/aaaa_test.rb +102 -0
  56. data/test/unit/rr/classes_test.rb +83 -0
  57. data/test/unit/rr/cname_test.rb +90 -0
  58. data/test/unit/rr/hinfo_test.rb +111 -0
  59. data/test/unit/rr/mr_test.rb +99 -0
  60. data/test/unit/rr/mx_test.rb +106 -0
  61. data/test/unit/rr/ns_test.rb +80 -0
  62. data/test/unit/rr/types_test.rb +71 -0
  63. data/test/unit/rr_test.rb +127 -0
  64. metadata +172 -0
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - jruby-9.1.5.0
10
+ - ruby-head
11
+
12
+ cache:
13
+ - bundler
@@ -0,0 +1,113 @@
1
+ # Changelog
2
+
3
+ ## Release 0.9.1
4
+
5
+ - FIXED: Fixed undefined 'size' errors (https://gitlab.com/gitlab-org/gitlab-net-dns/merge_requests/2)
6
+
7
+ - CHANGED: Test with GitLab CI (https://gitlab.com/gitlab-org/gitlab-net-dns/merge_requests/1)
8
+
9
+ ## Release 0.9.0
10
+
11
+ - FIXED: Fixed CI run (GH-77).
12
+
13
+ - FIXED: Fixed deprecated references to Fixnum.
14
+
15
+ - CHANGED: Major code cleanup.
16
+
17
+ - CHANGED: Minimum Ruby version is now 2.1
18
+
19
+
20
+ ## Release 0.8.0
21
+
22
+ - FIXED: undefined local variable or method `source_address_inet6' (GH-40). [Thanks @simsicon]
23
+
24
+ - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). [Thanks @nicholasren]
25
+
26
+ - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). [Thanks @ebroder]
27
+
28
+ - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). [Thanks @johnroa]
29
+
30
+ - CHANGED: Removed setup.rb installation script.
31
+
32
+
33
+ ## Release 0.7.1
34
+
35
+ - FIXED: Invalid file permissions on several files (GH-35) [Thanks @jamespharaoh]
36
+
37
+
38
+ ## Release 0.7.0
39
+
40
+ - ADDED: Added (experimental) Support for HINFO record.
41
+
42
+ - FIXED: Use Net::DNS::Resolver::Error class (not ResolverError, which does not exist).
43
+
44
+ - FIXED: Cleaned up require dependency and recursive require statements.
45
+
46
+ - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) [Thanks @shadowbq, @eik3]
47
+
48
+ - FIXED: SRV record not required by Net::DNS::RR (GH-27) [Thanks @sebastian]
49
+
50
+ - FIXED: Resolver now supports IPv6 (GH-32) [Thanks @jamesotron]
51
+
52
+ - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) [Thanks @dd23]
53
+
54
+ - FIXED: Net::DNS::Question changes input arguments (GH-7) [Thanks @gfarfl]
55
+
56
+ - CHANGED: Refactoring unit test to follow most used Ruby conventions.
57
+
58
+ - CHANGED: Rewritten and simplified Net::DNS::Classes. Improved test harness.
59
+
60
+ - CHANGED: Removed Jeweler development dependency.
61
+
62
+ - CHANGED: The library is now compatible with Bundler.
63
+
64
+ - CHANGED: Minimum supported Ruby version changed to Ruby 1.8.7.
65
+
66
+ - CHANGED: Rescue NameError so unsupported record types only result in a warning.
67
+
68
+ - CHANGED: Renamed Net::DNS::Resolver#send to Net::DNS::Resolver#query to avoid overriding default meaning of send method.
69
+
70
+
71
+ ## Release 0.6.1
72
+
73
+ - ADDED: Net::DNS::Packet#to_s method (alias of #inspect)
74
+
75
+ - FIXED: typo in lib/net/dns/rr/ptr.rb [Thanks Chris Lundquist]
76
+
77
+ - FIXED: warning: method redefined; discarding old inspect (GH-3) [Thanks Kevin Baker]
78
+
79
+ - FIXED: issue with rescue ArgumentError (GH-5) and with IPAddr handling (GH-6)
80
+
81
+
82
+ ## Release 0.6.0
83
+
84
+ *WARNING:- If you are upgrading from a previous minor release, check out the Compatibility issue list below.
85
+
86
+ - FIXED: Added missing #to_s method to Net::DNS::Question.
87
+
88
+ - FIXED: Compatibility with Ruby 1.9
89
+
90
+ - FIXED: Types regexp order issue
91
+
92
+ - CHANGED: Refactoring unit test to follow most used Ruby conventions
93
+
94
+ - CHANGED: default timeout is now 5 seconds for both UDP and TCP
95
+
96
+ - 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.
97
+
98
+ ### Compatibility issues
99
+
100
+ - CHANGED: RR#set_stype scope is now private to prevent invalid usage.
101
+
102
+ - CHANGED: DnsTimeout#timeout now raises LocalJumpError instead of DnsTimeoutArgumentError when block is missing.
103
+
104
+ - CHANGED: Renamed Net::DNS::RR::Types::Types to Net::DNS::RR::Types::TYPES to follow Ruby coding standards.
105
+
106
+
107
+ ## Release 0.4
108
+
109
+ - many bug fixes (thanks guys!)
110
+ - a whole new class Net::DNS::Header::RCode
111
+ - new methods in Net::DNS::Resolver class to do AXFR queries
112
+ - a new SRV resource record written by Dan Janowski
113
+ - more documentation written and corrected
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "minitest"
6
+ gem "minitest-reporters"
7
+ gem "rspec"
8
+ gem "rubocop", require: false
9
+ gem "rubocop-performance", require: false
@@ -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.
@@ -0,0 +1,172 @@
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 >= 2.1
16
+
17
+
18
+ ## Installation
19
+
20
+ The best way to install this library is via [RubyGems](https://rubygems.org/).
21
+
22
+ ```
23
+ gem install net-dns
24
+ ```
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
+ ```ruby
37
+ require 'rubygems'
38
+ require 'net/dns'
39
+ p Resolver("www.google.com")
40
+ ```
41
+
42
+ The output is compatible with BIND zone files and it's the same you would get with the dig utility.
43
+
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
+ ```
73
+
74
+ An optional block can be passed yielding the Net::DNS::Packet object
75
+
76
+ ```ruby
77
+ Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
78
+ # => 484 bytes
79
+ ```
80
+
81
+ Same for Net::DNS::Resolver.start():
82
+
83
+ ```ruby
84
+ Net::DNS::Resolver.start("google.com").answer.size
85
+ # => 5
86
+ ```
87
+
88
+ As optional parameters, +TYPE+ and +CLASS+ can be specified.
89
+
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
+
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
+ ```
110
+
111
+ ## Handling the response packet
112
+
113
+ The method Net::DNS::Resolver.start is a wrapper around Resolver.new. It returns a new Net::DNS::Packet object.
114
+
115
+ A DNS packet is divided into 5 sections:
116
+
117
+ - header section # => a Net::DNS::Header object
118
+ - question section # => a Net::DNS::Question object
119
+ - answer section # => an Array of Net::DNS::RR objects
120
+ - authority section # => an Array of Net::DNS::RR objects
121
+ - additional section # => an Array of Net::DNS::RR objects
122
+
123
+ You can access each section by calling the attribute with the same name on a Packet object:
124
+
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
+
137
+ The output is
138
+
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
+ ```
146
+
147
+ A better way to handle the answer section is to use the iterators directly on a Packet object:
148
+
149
+ ```ruby
150
+ packet.each_address do |ip|
151
+ puts "#{ip} is alive" if Ping.pingecho(ip.to_s, 10, 80)
152
+ end
153
+ ```
154
+
155
+ Gives:
156
+
157
+ ```
158
+ 74.125.45.100 is alive
159
+ 74.125.67.100 is alive
160
+ 209.85.171.100 is alive
161
+ ```
162
+
163
+
164
+ ## License
165
+
166
+ Net::DNS is distributed under the same license Ruby is.
167
+
168
+
169
+ ## Authors
170
+
171
+ - Marco Ceresa (@bluemonk)
172
+ - Simone Carletti (@weppos)
@@ -0,0 +1,38 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ # Run test by default.
4
+ task default: :test
5
+ task test: %i[testunit spec]
6
+
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new(:testunit) do |t|
10
+ t.libs = %w[lib test]
11
+ t.pattern = "test/**/*_test.rb"
12
+ t.verbose = !ENV["VERBOSE"].nil?
13
+ t.warning = !ENV["WARNING"].nil?
14
+ end
15
+
16
+ require "rubocop/rake_task"
17
+
18
+ RuboCop::RakeTask.new
19
+
20
+ require 'rspec/core/rake_task'
21
+ begin
22
+ require 'fuubar'
23
+ rescue LoadError
24
+ end
25
+
26
+ RSpec::Core::RakeTask.new do |t|
27
+ t.verbose = !!ENV["VERBOSE"]
28
+ t.rspec_opts = []
29
+ t.rspec_opts << ['--format', 'Fuubar'] if defined?(Fuubar)
30
+ end
31
+
32
+ require 'yard/rake/yardoc_task'
33
+
34
+ YARD::Rake::YardocTask.new(:yardoc) do |y|
35
+ y.options = ["--output-dir", "yardoc"]
36
+ end
37
+
38
+ CLOBBER.include "yardoc"
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "net/dns"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start