Skip to content

Instantly share code, notes, and snippets.

@jim80net
Created February 18, 2014 16:39
Show Gist options
  • Save jim80net/9074537 to your computer and use it in GitHub Desktop.
Save jim80net/9074537 to your computer and use it in GitHub Desktop.
Compare DNS output with a list of expected values
#!/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
@jim80net
Copy link
Author

$> cat worklist.txt
asd.com 1.2.3.4
asd2.com 1.2.3.5
$>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment