Last active
August 29, 2015 14:16
-
-
Save justinledwards/5a66054fbbefb0f5c8e8 to your computer and use it in GitHub Desktop.
Cisco ASA Auto Documentation
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
#running-config.cfg | |
require 'resolv' | |
i = 0 | |
parent_count = 0 | |
network = false | |
network_count = 0 | |
host_count = 0 | |
last_host_network = 0 | |
description_count = 0 | |
child_type = "" | |
host = "" | |
description = "" | |
output = false | |
last_output = 0 | |
hostname = "" | |
resolver = Resolv::DNS.new() | |
puts "ID, Address, Hostname, Comments" | |
IO.foreach("running-config.cfg") do |line| | |
i += 1 | |
if ( !line.match(/^\:|!/) ) | |
#puts "line" + i.to_s | |
if ( !line.match(/^\s/) ) | |
if (child_type != "nat") | |
if last_output != host_count | |
output = false | |
end | |
if !output && ( host != "" ) | |
begin | |
hostname = resolver.getname(host) | |
rescue | |
hostname = "UNDEFINED" | |
end | |
puts "#{host_count}, #{host}, #{hostname}, #{description}" | |
output = true | |
description = "" | |
last_output = host_count | |
end | |
end | |
parent_count += 1 | |
parent = line | |
#puts "#{parent_count}" | |
#unless line.match(/^\s/) | |
type = parent.split(" ")[0] | |
subtype = parent.split(" ")[1] | |
if ( type == "object" ) && ( subtype == "network" ) | |
temp_name = parent.split(" ")[2] | |
if ( !temp_name.match(/^obj/) ) | |
description = temp_name | |
end | |
network_count += 1 | |
#puts "#{network_count}" | |
network = true | |
else | |
network = false | |
end | |
#puts parent + " " + type | |
#puts "#{type}" | |
else | |
if network | |
#puts "I'm a network" | |
#puts line.split(" ")[0] | |
child_type = line.split(" ")[0] | |
if ( child_type == "host") | |
host_count += 1 | |
last_host_network = network_count | |
# get host ip | |
host = line.split(" ")[1] | |
#puts "Host: #{host}" | |
elsif ( child_type == "description") | |
# if network count stayed the same and parent count stayed the same change description var, else blank | |
if ( last_host_network == network_count ) | |
# get description | |
description_count += 1 | |
description = description + line.sub(" #{line.split(" ")[0]}", '') | |
#puts description | |
#description = line.split(" ")[1] | |
#puts "Description: #{description}" | |
else | |
description = "" | |
end | |
else | |
#puts "WTF" | |
end | |
# iterate over children | |
else | |
#puts "I'm not a network" | |
network = false | |
end | |
end | |
#out.puts line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment