Skip to content

Instantly share code, notes, and snippets.

@infowolfe
Created October 15, 2014 06:07
Show Gist options
  • Save infowolfe/5f47888a454962b05cb2 to your computer and use it in GitHub Desktop.
Save infowolfe/5f47888a454962b05cb2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from pprint import pprint
import re
f = open('pix-running_config', 'r')
table = {}
n2n = {}
idx = 0
s2len = 0
n2nlen = 0
s3len = 0
n3nlen = 0
with open('pix-running_config') as f:
for line in f:
s = line.split()
if s[0] == 'name':
n2n.update({s[2]: s[1]})
if s[0] == 'static':
if s[2] != 'tcp' and re.match('[a-z]', s[2]):
if len(s[2]) > s2len:
s2len = len(s[2])
if len(n2n[s[2]]) > n2nlen:
n2nlen = len(n2n[s[2]])
if len(s[3]) > s3len:
s3len = len(s[3])
if len(n2n[s[3]]) > n3nlen:
n3nlen = len(n2n[s[3]])
table.update({idx: [s[2], n2n[s[2]], s[3], n2n[s[3]]]})
idx += 1
# if you'd like to pretty-print
print "table dict:\t"
pprint(table)
print "\n\n\n"
print "format is pandoc-markdown:\n"
template = '{0:%s} {1:%s} {2:%s} {3:%s}' % (s2len, n2nlen, s3len, n3nlen)
print template.format("EXT Name", "EXT IP", "NAT Name", "INT IP", align="<")
print template.format("-"*s2len, "-"*n2nlen, "-"*s3len, "-"*n3nlen, align="<")
for list in list(table):
print template.format(*table[list])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment