Created
February 18, 2014 16:39
-
-
Save jim80net/9074537 to your computer and use it in GitHub Desktop.
Compare DNS output with a list of expected values
This file contains 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
#!/usr/bin/env ruby | |
require 'awesome_print' | |
require 'pry' | |
require 'ostruct' | |
require 'resolv' | |
begin #top | |
puts "Reading worklist" | |
objects = [] | |
File.readlines('worklist.txt').each { |v| | |
a = v.split(' ') | |
objects.push OpenStruct.new( | |
name: a[0], | |
shouldA: a[1] | |
) | |
} | |
puts "Loading DNS results" | |
@resolver = Resolv::DNS.new( nameserver: ['4.2.2.1'] ) | |
objects.each {|v| | |
v.digA = @resolver.getresources( v.name, Resolv::DNS::Resource::IN::A ) | |
unless v.digA == [] | |
print '.' | |
else | |
print 'F' | |
v.digA.push OpenStruct.new( address: 'DNS ERROR' ) | |
end | |
} | |
puts "\n" | |
puts "Analyzing results" | |
errors = objects.select {|v| v.digA[0].address.to_s != v.shouldA } | |
puts "#{errors.count } mismatches found" | |
ap errors | |
raise 'End of program' | |
rescue => e | |
puts "#{e.class}: #{e}" | |
pry | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$> cat worklist.txt
asd.com 1.2.3.4
asd2.com 1.2.3.5
$>