Created
April 25, 2014 17:57
-
-
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
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
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 |
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
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