Created
February 7, 2018 14:47
-
-
Save matiaskorhonen/68beda6d55d64fe8d13b7e692fcee079 to your computer and use it in GitHub Desktop.
Test script to help diagnose erroneous NXDOMAIN responses from Ubiquiti networking gear
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require "dnsruby" | |
rescue LoadError | |
puts "gem install dnsruby" | |
end | |
require "yaml/store" | |
include Dnsruby | |
trap("SIGINT") { exit 1 } | |
nameservers = [ | |
{ ip: "10.0.1.1", label: "local" }, | |
{ ip: "193.229.0.40", label: "elisa" }, | |
{ ip: "193.229.0.42", label: "elisa" }, | |
{ ip: "8.8.8.8", label: "google" }, | |
] | |
target = "static.squarespace.com" | |
store = YAML::Store.new "dns_results.yaml" | |
got_nx = false | |
until got_nx do | |
run_start = Time.now | |
results = nameservers.map do |ns, index| | |
nxdomain = false | |
res = Resolver.new(nameserver: [ns[:ip]]) | |
begin | |
ret = res.query(target) | |
rescue Dnsruby::NXDomain | |
nxdomain = got_nx = true | |
end | |
puts "#{ns[:label]} (#{ns[:ip]}):\tnxdomain: #{nxdomain}" | |
{ | |
ip: ns[:ip], | |
label: ns[:label], | |
results: ret.answer.map(&:to_s).join, | |
nxdomain: nxdomain, | |
} | |
end | |
store.transaction do | |
store["results"] ||= [] | |
store["results"] << { | |
run_start: run_start, | |
run_end: Time.now, | |
results: results | |
} | |
end | |
puts | |
sleep 5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment