5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dns_tools/ns_check.rb', line 5
def nscheck(domain)
root_resolver = Resolv::DNS.new(:nameserver => ['8.8.8.8', '141.1.1.1', '8.8.4.4'])
nameservers = root_resolver.getresources(domain, Resolv::DNS::Resource::IN::NS)
serials = []
for ns in nameservers
ns_resolver = Resolv::DNS.new(:nameserver => [ns.name.to_s])
print ns.name.to_s.ljust(30)
soa = ns_resolver.getresource(domain, Resolv::DNS::Resource::IN::SOA)
if soa
ip = root_resolver.getresource(ns.name.to_s, Resolv::DNS::Resource::IN::ANY)
print ip.address.to_s.ljust(25)
print soa.serial
serials << soa.serial
else
puts "No SOA record found"
end
puts
$stdout.flush
end
if serials.uniq.size == 1
puts "\e[32mAll nameservers have the same serial\e[0m"
elsif serials.empty?
puts "No nameservers found for #{domain}"
else
puts "\e[31mNot all nameservers have the same records\e[0m"
end
end
|