Skip to content

Instantly share code, notes, and snippets.

@elmariofredo
Created April 25, 2014 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmariofredo/11297974 to your computer and use it in GitHub Desktop.
Save elmariofredo/11297974 to your computer and use it in GitHub Desktop.
Check DNS zone file using simple ruby script and verify presence of A and CNAME records using csv file
require "csv"
csv = CSV.new(File.read('zone.csv'))
dns_servers = ["ns1.dns.net", "ns1.otherdns.net"]
csv.each do |row|
type = row[0]
name = row[1].lstrip
result = row[2].lstrip
if name == "@"
host = "trexglobal.com"
else
host = "#{name}.trexglobal.com"
end
result = "#{result}." if type == "CNAME"
puts "#{host} #{type}"
dns_servers.each do |dns|
command = "/usr/bin/dig @#{dns} #{host} #{type} +short"
if type == "MX" or type == "TXT"
puts "Skipping: #{command}"
next
end
round = `#{command}`
if round.gsub("\n", '') == result
puts " on #{dns} OK"
else
puts " on #{dns} FAIL"
puts "#{round.gsub("\n", '')} != #{result}"
puts "#{command}"
end
end
end
A @ 1.1.11.1
A bugzilla 1.1.11.1
A cl1 1.1.11.1
A cl2 1.1.11.1
CNAME deploy mc.example.com
CNAME www something.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment