rubydns 0.6.0 → 2.0.0
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.
- checksums.yaml +6 -14
- data/.gitignore +23 -14
- data/.rspec +4 -0
- data/.simplecov +15 -0
- data/.travis.yml +9 -5
- data/.yardopts +1 -0
- data/Gemfile +6 -2
- data/README.md +82 -92
- data/Rakefile +2 -5
- data/bin/rubydns-check +374 -0
- data/examples/Gemfile +7 -0
- data/examples/README.md +137 -0
- data/examples/basic-dns.rb +24 -0
- data/examples/cname.rb +25 -0
- data/{test/examples/dropping-dns.rb → examples/flakey-dns.rb} +28 -31
- data/{test/examples → examples}/fortune-dns.rb +42 -46
- data/examples/geoip-dns.rb +115 -0
- data/examples/simple.rb +25 -0
- data/{test/examples → examples}/soa-dns.rb +27 -27
- data/{test/examples → examples}/test-dns-1.rb +26 -20
- data/{test/examples → examples}/test-dns-2.rb +17 -19
- data/examples/wikipedia-dns.rb +107 -0
- data/lib/rubydns/rule_based_server.rb +180 -0
- data/lib/rubydns/version.rb +1 -1
- data/lib/rubydns.rb +13 -63
- data/rubydns.gemspec +29 -23
- data/spec/rubydns/daemon_spec.rb +114 -0
- data/{test/test_system.rb → spec/rubydns/injected_supervisor_spec.rb} +32 -25
- data/spec/rubydns/passthrough_spec.rb +85 -0
- data/spec/rubydns/rules_spec.rb +74 -0
- data/spec/spec_helper.rb +30 -0
- metadata +101 -78
- data/bin/rd-dns-check +0 -374
- data/bin/rd-resolve-test +0 -160
- data/lib/rubydns/chunked.rb +0 -34
- data/lib/rubydns/extensions/hexdump.rb +0 -38
- data/lib/rubydns/extensions/logger.rb +0 -30
- data/lib/rubydns/extensions/resolv.rb +0 -53
- data/lib/rubydns/extensions/string-1.8.rb +0 -35
- data/lib/rubydns/extensions/string-1.9.2.rb +0 -29
- data/lib/rubydns/extensions/string-1.9.3.rb +0 -31
- data/lib/rubydns/extensions/string.rb +0 -27
- data/lib/rubydns/handler.rb +0 -140
- data/lib/rubydns/message.rb +0 -41
- data/lib/rubydns/resolver.rb +0 -239
- data/lib/rubydns/server.rb +0 -241
- data/lib/rubydns/system.rb +0 -146
- data/lib/rubydns/transaction.rb +0 -250
- data/test/examples/geoip-dns.rb +0 -86
- data/test/helper.rb +0 -9
- data/test/test_daemon.rb +0 -100
- data/test/test_domains.txt +0 -185
- data/test/test_passthrough.rb +0 -80
- data/test/test_resolver.rb +0 -105
- data/test/test_rules.rb +0 -74
- data/test/test_slow_server.rb +0 -98
- data/test/test_truncation.rb +0 -78
- /data/{test → spec/rubydns}/hosts.txt +0 -0
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
if ENV['COVERAGE'] || ENV['TRAVIS']
|
|
3
|
+
begin
|
|
4
|
+
require 'simplecov'
|
|
5
|
+
|
|
6
|
+
SimpleCov.start do
|
|
7
|
+
add_filter "/spec/"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
if ENV['TRAVIS']
|
|
11
|
+
require 'coveralls'
|
|
12
|
+
Coveralls.wear!
|
|
13
|
+
end
|
|
14
|
+
rescue LoadError
|
|
15
|
+
warn "Could not load simplecov: #{$!}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
require "bundler/setup"
|
|
20
|
+
require "async"
|
|
21
|
+
require "async/rspec"
|
|
22
|
+
|
|
23
|
+
RSpec.configure do |config|
|
|
24
|
+
# Enable flags like --only-failures and --next-failure
|
|
25
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
|
26
|
+
|
|
27
|
+
config.expect_with :rspec do |c|
|
|
28
|
+
c.syntax = :expect
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,100 +1,133 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubydns
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: async-dns
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.
|
|
19
|
+
version: '1.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.
|
|
26
|
+
version: '1.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: async-rspec
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - ~>
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.0
|
|
34
|
-
type: :
|
|
33
|
+
version: '1.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.4'
|
|
62
|
+
type: :development
|
|
35
63
|
prerelease: false
|
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
65
|
requirements:
|
|
38
|
-
- - ~>
|
|
66
|
+
- - "~>"
|
|
39
67
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
version: '3.4'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: "\t\tRubyDNS is a high-performance DNS server which can be easily integrated
|
|
84
|
+
into\n\t\tother projects or used as a stand-alone daemon. By default it uses\n\t\trule-based
|
|
85
|
+
pattern matching. Results can be hard-coded, computed, fetched from\n\t\ta remote
|
|
86
|
+
DNS server or fetched from a local cache, depending on requirements.\n\n\t\tIn addition,
|
|
87
|
+
RubyDNS includes a high-performance asynchronous DNS resolver\n\t\tbuilt on top
|
|
88
|
+
of Celluloid. This module can be used by itself in client\n\t\tapplications without
|
|
89
|
+
using the full RubyDNS server stack.\n"
|
|
48
90
|
email:
|
|
49
91
|
- samuel.williams@oriontransfer.co.nz
|
|
50
92
|
executables:
|
|
51
|
-
-
|
|
52
|
-
- rd-resolve-test
|
|
93
|
+
- rubydns-check
|
|
53
94
|
extensions: []
|
|
54
95
|
extra_rdoc_files: []
|
|
55
96
|
files:
|
|
56
|
-
- .gitignore
|
|
57
|
-
- .
|
|
97
|
+
- ".gitignore"
|
|
98
|
+
- ".rspec"
|
|
99
|
+
- ".simplecov"
|
|
100
|
+
- ".travis.yml"
|
|
101
|
+
- ".yardopts"
|
|
58
102
|
- Gemfile
|
|
59
103
|
- README.md
|
|
60
104
|
- Rakefile
|
|
61
|
-
- bin/
|
|
62
|
-
-
|
|
105
|
+
- bin/rubydns-check
|
|
106
|
+
- examples/Gemfile
|
|
107
|
+
- examples/README.md
|
|
108
|
+
- examples/basic-dns.rb
|
|
109
|
+
- examples/cname.rb
|
|
110
|
+
- examples/flakey-dns.rb
|
|
111
|
+
- examples/fortune-dns.rb
|
|
112
|
+
- examples/geoip-dns.rb
|
|
113
|
+
- examples/simple.rb
|
|
114
|
+
- examples/soa-dns.rb
|
|
115
|
+
- examples/test-dns-1.rb
|
|
116
|
+
- examples/test-dns-2.rb
|
|
117
|
+
- examples/wikipedia-dns.rb
|
|
63
118
|
- lib/rubydns.rb
|
|
64
|
-
- lib/rubydns/
|
|
65
|
-
- lib/rubydns/extensions/hexdump.rb
|
|
66
|
-
- lib/rubydns/extensions/logger.rb
|
|
67
|
-
- lib/rubydns/extensions/resolv.rb
|
|
68
|
-
- lib/rubydns/extensions/string-1.8.rb
|
|
69
|
-
- lib/rubydns/extensions/string-1.9.2.rb
|
|
70
|
-
- lib/rubydns/extensions/string-1.9.3.rb
|
|
71
|
-
- lib/rubydns/extensions/string.rb
|
|
72
|
-
- lib/rubydns/handler.rb
|
|
73
|
-
- lib/rubydns/message.rb
|
|
74
|
-
- lib/rubydns/resolver.rb
|
|
75
|
-
- lib/rubydns/server.rb
|
|
76
|
-
- lib/rubydns/system.rb
|
|
77
|
-
- lib/rubydns/transaction.rb
|
|
119
|
+
- lib/rubydns/rule_based_server.rb
|
|
78
120
|
- lib/rubydns/version.rb
|
|
79
121
|
- rubydns.gemspec
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
-
|
|
89
|
-
- test/test_domains.txt
|
|
90
|
-
- test/test_passthrough.rb
|
|
91
|
-
- test/test_resolver.rb
|
|
92
|
-
- test/test_rules.rb
|
|
93
|
-
- test/test_slow_server.rb
|
|
94
|
-
- test/test_system.rb
|
|
95
|
-
- test/test_truncation.rb
|
|
96
|
-
homepage: https://github.com/ioquatix/rubydns
|
|
97
|
-
licenses: []
|
|
122
|
+
- spec/rubydns/daemon_spec.rb
|
|
123
|
+
- spec/rubydns/hosts.txt
|
|
124
|
+
- spec/rubydns/injected_supervisor_spec.rb
|
|
125
|
+
- spec/rubydns/passthrough_spec.rb
|
|
126
|
+
- spec/rubydns/rules_spec.rb
|
|
127
|
+
- spec/spec_helper.rb
|
|
128
|
+
homepage: http://www.codeotaku.com/projects/rubydns
|
|
129
|
+
licenses:
|
|
130
|
+
- MIT
|
|
98
131
|
metadata: {}
|
|
99
132
|
post_install_message:
|
|
100
133
|
rdoc_options: []
|
|
@@ -102,34 +135,24 @@ require_paths:
|
|
|
102
135
|
- lib
|
|
103
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
137
|
requirements:
|
|
105
|
-
- -
|
|
138
|
+
- - ">="
|
|
106
139
|
- !ruby/object:Gem::Version
|
|
107
|
-
version:
|
|
140
|
+
version: 2.2.6
|
|
108
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
142
|
requirements:
|
|
110
|
-
- -
|
|
143
|
+
- - ">="
|
|
111
144
|
- !ruby/object:Gem::Version
|
|
112
145
|
version: '0'
|
|
113
146
|
requirements: []
|
|
114
147
|
rubyforge_project:
|
|
115
|
-
rubygems_version: 2.
|
|
148
|
+
rubygems_version: 2.6.10
|
|
116
149
|
signing_key:
|
|
117
150
|
specification_version: 4
|
|
118
151
|
summary: An easy to use DNS server and resolver for Ruby.
|
|
119
152
|
test_files:
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
- test/helper.rb
|
|
127
|
-
- test/hosts.txt
|
|
128
|
-
- test/test_daemon.rb
|
|
129
|
-
- test/test_domains.txt
|
|
130
|
-
- test/test_passthrough.rb
|
|
131
|
-
- test/test_resolver.rb
|
|
132
|
-
- test/test_rules.rb
|
|
133
|
-
- test/test_slow_server.rb
|
|
134
|
-
- test/test_system.rb
|
|
135
|
-
- test/test_truncation.rb
|
|
153
|
+
- spec/rubydns/daemon_spec.rb
|
|
154
|
+
- spec/rubydns/hosts.txt
|
|
155
|
+
- spec/rubydns/injected_supervisor_spec.rb
|
|
156
|
+
- spec/rubydns/passthrough_spec.rb
|
|
157
|
+
- spec/rubydns/rules_spec.rb
|
|
158
|
+
- spec/spec_helper.rb
|
data/bin/rd-dns-check
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
|
3
|
-
#
|
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
# furnished to do so, subject to the following conditions:
|
|
10
|
-
#
|
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
|
12
|
-
# all copies or substantial portions of the Software.
|
|
13
|
-
#
|
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
# THE SOFTWARE.
|
|
21
|
-
|
|
22
|
-
# Pulls down DNS data from old-dns
|
|
23
|
-
# rd-dns-check -s old-dns.mydomain.com -d mydomain.com. -f old-dns.yml
|
|
24
|
-
|
|
25
|
-
# Check data against old-dns
|
|
26
|
-
# rd-dns-check -s old-dns.mydomain.com -d mydomain.com. -c old-dns.yml
|
|
27
|
-
|
|
28
|
-
# Check data against new DNS server
|
|
29
|
-
# rd-dns-check -s 10.0.0.36 -d mydomain.com. -c old-dns.yml
|
|
30
|
-
|
|
31
|
-
require 'yaml'
|
|
32
|
-
require 'optparse'
|
|
33
|
-
require 'set'
|
|
34
|
-
|
|
35
|
-
class DNSRecord
|
|
36
|
-
def initialize(arr)
|
|
37
|
-
@record = arr
|
|
38
|
-
normalize
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def normalize
|
|
42
|
-
@record[0] = @record[0].downcase
|
|
43
|
-
@record[1] = @record[1].upcase
|
|
44
|
-
@record[2] = @record[2].upcase
|
|
45
|
-
@record[3] = @record[3].downcase
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def hostname
|
|
49
|
-
@record[0]
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def klass
|
|
53
|
-
@record[1]
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def type
|
|
57
|
-
@record[2]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def value
|
|
61
|
-
@record[3]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def is_address?
|
|
65
|
-
["A", "AAAA"].include?(type)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def is_cname?
|
|
69
|
-
return type == "CNAME"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def to_s
|
|
73
|
-
"#{hostname.ljust(50)} #{klass.rjust(4)} #{type.rjust(5)} #{value}"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def key
|
|
77
|
-
"#{hostname}:#{klass}:#{type}".downcase
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def to_a
|
|
81
|
-
@record
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def == other
|
|
85
|
-
return @record == other.to_a
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def dig(dns_server, cmd, exclude = ["TXT", "HINFO", "SOA", "NS"])
|
|
90
|
-
records = []
|
|
91
|
-
|
|
92
|
-
IO.popen("dig @#{dns_server} +nottlid +nocmd +noall +answer " + cmd) do |p|
|
|
93
|
-
p.each do |line|
|
|
94
|
-
r = line.chomp.split(/\s/, 4)
|
|
95
|
-
|
|
96
|
-
next if exclude.include?(r[2])
|
|
97
|
-
|
|
98
|
-
records << DNSRecord.new(r)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
return records
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def retrieve_records(dns_server, dns_root)
|
|
106
|
-
return dig(dns_server, "#{dns_root} AXFR")
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def resolve_hostname(dns_server, hostname)
|
|
110
|
-
return dig(dns_server, "#{hostname} A").first
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def resolve_address(dns_server, address)
|
|
114
|
-
return dig(dns_server, "-x #{address}").first
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def print_summary(records, errors, okay, &block)
|
|
118
|
-
puts "[ Summary ]".center(72, "=")
|
|
119
|
-
puts "Checked #{records.size} record(s). #{errors} errors."
|
|
120
|
-
if errors == 0
|
|
121
|
-
puts "Everything seemed okay."
|
|
122
|
-
else
|
|
123
|
-
puts "The following records are okay:"
|
|
124
|
-
okay.each do |r|
|
|
125
|
-
if block_given?
|
|
126
|
-
yield r
|
|
127
|
-
else
|
|
128
|
-
puts "".rjust(12) + r.to_s
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Resolve hostnames to IP address "A" or "AAAA" records.
|
|
135
|
-
# Works through CNAME records in order to find out the final
|
|
136
|
-
# address if possible. Checks for loops in CNAME records.
|
|
137
|
-
def resolve_addresses(records)
|
|
138
|
-
addresses = {}
|
|
139
|
-
cnames = {}
|
|
140
|
-
|
|
141
|
-
# Extract all hostname -> ip address mappings
|
|
142
|
-
records.each do |r|
|
|
143
|
-
if r.is_address?
|
|
144
|
-
addresses[r.hostname] = r
|
|
145
|
-
elsif r.is_cname?
|
|
146
|
-
cnames[r.hostname] = r
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
cnames.each do |hostname, r|
|
|
151
|
-
q = r
|
|
152
|
-
trail = []
|
|
153
|
-
failed = false
|
|
154
|
-
|
|
155
|
-
# Keep track of CNAME records to avoid loops
|
|
156
|
-
while q.is_cname?
|
|
157
|
-
trail << q
|
|
158
|
-
q = cnames[q.value] || addresses[q.value]
|
|
159
|
-
|
|
160
|
-
# Q could be nil at this point, which means there was no address record
|
|
161
|
-
# Q could be already part of the trail, which means there was a loop
|
|
162
|
-
if q == nil || trail.include?(q)
|
|
163
|
-
failed = true
|
|
164
|
-
break
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
if failed
|
|
169
|
-
q = trail.last
|
|
170
|
-
puts "*** Warning: CNAME record #{hostname} does not point to actual address!"
|
|
171
|
-
trail.each_with_index do |r, idx|
|
|
172
|
-
puts idx.to_s.rjust(10) + ": " + r.to_s
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
addresses[r.hostname] = q
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
return addresses, cnames
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def check_reverse(records, dns_server)
|
|
183
|
-
errors = 0
|
|
184
|
-
okay = []
|
|
185
|
-
|
|
186
|
-
puts "[ Checking Reverse Lookups ]".center(72, "=")
|
|
187
|
-
|
|
188
|
-
records.each do |r|
|
|
189
|
-
next unless r.is_address?
|
|
190
|
-
|
|
191
|
-
sr = resolve_address(dns_server, r.value)
|
|
192
|
-
|
|
193
|
-
if sr == nil
|
|
194
|
-
puts "*** Could not resolve host"
|
|
195
|
-
puts "".rjust(12) + r.to_s
|
|
196
|
-
errors += 1
|
|
197
|
-
elsif r.hostname != sr.value
|
|
198
|
-
puts "*** Hostname does not match"
|
|
199
|
-
puts "Primary: ".rjust(12) + r.to_s
|
|
200
|
-
puts "Secondary: ".rjust(12) + sr.to_s
|
|
201
|
-
errors += 1
|
|
202
|
-
else
|
|
203
|
-
okay << [r, sr]
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
print_summary(records, errors, okay) do |r|
|
|
208
|
-
puts "Primary:".rjust(12) + r[0].to_s
|
|
209
|
-
puts "Secondary:".rjust(12) + r[1].to_s
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def ping_records(records)
|
|
214
|
-
addresses, cnames = resolve_addresses(records)
|
|
215
|
-
|
|
216
|
-
errors = 0
|
|
217
|
-
okay = []
|
|
218
|
-
|
|
219
|
-
puts "[ Pinging Records ]".center(72, "=")
|
|
220
|
-
|
|
221
|
-
addresses.each do |hostname, r|
|
|
222
|
-
ping = "ping -c 5 -t 5 -i 1 -o #{r.value} > /dev/null"
|
|
223
|
-
|
|
224
|
-
system(ping)
|
|
225
|
-
|
|
226
|
-
if $?.exitstatus == 0
|
|
227
|
-
okay << r
|
|
228
|
-
else
|
|
229
|
-
puts "*** Could not ping host #{hostname.dump}: #{ping.dump}"
|
|
230
|
-
puts "".rjust(12) + r.to_s
|
|
231
|
-
errors += 1
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
print_summary(records, errors, okay)
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def query_records(primary, secondary_server)
|
|
239
|
-
addresses, cnames = resolve_addresses(primary)
|
|
240
|
-
|
|
241
|
-
okay = []
|
|
242
|
-
errors = 0
|
|
243
|
-
|
|
244
|
-
primary.each do |r|
|
|
245
|
-
sr = resolve_hostname(secondary_server, r.hostname)
|
|
246
|
-
|
|
247
|
-
if sr == nil
|
|
248
|
-
puts "*** Could not resolve hostname #{r.hostname.dump}"
|
|
249
|
-
puts "Primary: ".rjust(12) + r.to_s
|
|
250
|
-
|
|
251
|
-
rsr = resolve_address(secondary_server, (addresses[r.value] || r).value)
|
|
252
|
-
puts "Address: ".rjust(12) + rsr.to_s if rsr
|
|
253
|
-
|
|
254
|
-
errors += 1
|
|
255
|
-
elsif sr.value != r.value
|
|
256
|
-
ra = addresses[r.value] if r.is_cname?
|
|
257
|
-
sra = addresses[sr.value] if sr.is_cname?
|
|
258
|
-
|
|
259
|
-
if (sra || sr).value != (ra || r).value
|
|
260
|
-
puts "*** IP Address does not match"
|
|
261
|
-
puts "Primary: ".rjust(12) + r.to_s
|
|
262
|
-
puts "Resolved: ".rjust(12) + ra.to_s if ra
|
|
263
|
-
puts "Secondary: ".rjust(12) + sr.to_s
|
|
264
|
-
puts "Resolved: ".rjust(12) + sra.to_s if sra
|
|
265
|
-
errors += 1
|
|
266
|
-
end
|
|
267
|
-
else
|
|
268
|
-
okay << r
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
print_summary(primary, errors, okay)
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
def check_records(primary, secondary)
|
|
276
|
-
s = {}
|
|
277
|
-
okay = []
|
|
278
|
-
errors = 0
|
|
279
|
-
|
|
280
|
-
secondary.each do |r|
|
|
281
|
-
s[r.key] = r
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
puts "[ Checking Records ]".center(72, "=")
|
|
285
|
-
|
|
286
|
-
primary.each do |r|
|
|
287
|
-
sr = s[r.key]
|
|
288
|
-
|
|
289
|
-
if sr == nil
|
|
290
|
-
puts "*** Could not find record"
|
|
291
|
-
puts "Primary: ".rjust(12) + r.to_s
|
|
292
|
-
errors += 1
|
|
293
|
-
elsif sr != r
|
|
294
|
-
puts "*** Records are different"
|
|
295
|
-
puts "Primary: ".rjust(12) + r.to_s
|
|
296
|
-
puts "Secondary: ".rjust(12) + sr.to_s
|
|
297
|
-
errors += 1
|
|
298
|
-
else
|
|
299
|
-
okay << r
|
|
300
|
-
end
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
print_summary(primary, errors, okay)
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
OPTIONS = {
|
|
307
|
-
:DNSServer => nil,
|
|
308
|
-
:DNSRoot => ".",
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
ARGV.options do |o|
|
|
312
|
-
script_name = File.basename($0)
|
|
313
|
-
|
|
314
|
-
o.set_summary_indent(' ')
|
|
315
|
-
o.banner = "Usage: #{script_name} [options]"
|
|
316
|
-
o.define_head "This script is designed to test and check DNS servers."
|
|
317
|
-
|
|
318
|
-
o.on("-s ns.my.domain.", "--server ns.my.domain.", String, "The DNS server to query.") { |host| OPTIONS[:DNSServer] = host }
|
|
319
|
-
o.on("-d my.domain.", "--domain my.domain.", String, "The DNS zone to transfer/test.") { |host| OPTIONS[:DNSRoot] = host }
|
|
320
|
-
|
|
321
|
-
o.on("-f output.yml", "--fetch output.yml", String, "Pull down a list of hosts. Filters TXT and HINFO records. DNS transfers must be enabled.") { |f|
|
|
322
|
-
records = retrieve_records(OPTIONS[:DNSServer], OPTIONS[:DNSRoot])
|
|
323
|
-
|
|
324
|
-
output = (f ? File.open(f, "w") : STDOUT)
|
|
325
|
-
|
|
326
|
-
output.write(YAML::dump(records))
|
|
327
|
-
|
|
328
|
-
puts "#{records.size} record(s) retrieved."
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
o.on("-c input.yml", "--check input.yml", String, "Check that the DNS server returns results as specified by the file.") { |f|
|
|
332
|
-
input = (f ? File.open(f) : STDIN)
|
|
333
|
-
|
|
334
|
-
master_records = YAML::load(input.read)
|
|
335
|
-
secondary_records = retrieve_records(OPTIONS[:DNSServer], OPTIONS[:DNSRoot])
|
|
336
|
-
|
|
337
|
-
check_records(master_records, secondary_records)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
o.on("-q input.yml", "--query input.yml", String, "Query the remote DNS server with all hostnames in the given file, and checks the IP addresses are consistent.") { |f|
|
|
341
|
-
input = (f ? File.open(f) : STDIN)
|
|
342
|
-
|
|
343
|
-
master_records = YAML::load(input.read)
|
|
344
|
-
|
|
345
|
-
query_records(master_records, OPTIONS[:DNSServer])
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
o.on("-p input.yml", "--ping input.yml", String, "Ping all hosts to check if they are available or not.") { |f|
|
|
349
|
-
input = (f ? File.open(f) : STDIN)
|
|
350
|
-
|
|
351
|
-
master_records = YAML::load(input.read)
|
|
352
|
-
|
|
353
|
-
ping_records(master_records)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
o.on("-r input.yml", "--reverse input.yml", String, "Check that all address records have appropriate reverse entries.") { |f|
|
|
357
|
-
input = (f ? File.open(f) : STDIN)
|
|
358
|
-
|
|
359
|
-
master_records = YAML::load(input.read)
|
|
360
|
-
|
|
361
|
-
check_reverse(master_records, OPTIONS[:DNSServer])
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
o.separator ""
|
|
365
|
-
o.separator "Help and Copyright information"
|
|
366
|
-
|
|
367
|
-
o.on_tail("--copy", "Display copyright information") {
|
|
368
|
-
puts "#{script_name}. Copyright (c) 2009, 2011 Samuel Williams. Released under the MIT license."
|
|
369
|
-
puts "See http://www.oriontransfer.co.nz/ for more information."
|
|
370
|
-
exit
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
|
|
374
|
-
end.parse!
|