Created
February 5, 2009 16:07
-
-
Save d-tux/58781 to your computer and use it in GitHub Desktop.
Reads Bind zone files
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
#!/usr/bin/ruby | |
def resolve_node(node) | |
return node if node[-1] == '.'[0] | |
return node unless $context.has_key? "ORIGIN" | |
return "#{node}.#{$context["ORIGIN"]}" | |
end | |
ARGS.each do |filename| | |
File.open filename, 'r' do |file| | |
$context = {} | |
file.each_line do |line| | |
if line.match /^\$([A-Z]+)\s+(.*)/ then | |
key, value = $1.strip, $2.sub(/\s*;.*$/, '').strip | |
$context[key] = value | |
elsif line.match /(\S+)\s+(A|CNAME)\s+(\S+)/ then | |
node = resolve_node $1.strip | |
type = $2.strip | |
pointer = $3.sub(/\s*;.*$/, '').strip | |
action = case type | |
when "A" then | |
"is homed at" | |
when "CNAME" then | |
pointer = resolve_node pointer | |
"is an alias for" | |
else | |
nil | |
end | |
unless action.nil? | |
puts "#{node} #{action} #{pointer}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment