Skip to content

Instantly share code, notes, and snippets.

@jeremyvisser
Created September 22, 2012 05:58
Show Gist options
  • Save jeremyvisser/3765294 to your computer and use it in GitHub Desktop.
Save jeremyvisser/3765294 to your computer and use it in GitHub Desktop.
Internode to Cisco ACL
#!/usr/bin/env python
# usage:
#
# wget https://customer-webtools-api.internode.on.net/unmetered_ip_address_list.txt
# ./node-to-acl < unmetered_ip_address_list.txt
import sys
import ipaddr
try:
line_num = int(sys.argv[1])
except IndexError:
line_num = None
for l in sys.stdin:
l = l[:-1] # remove trailing newline
if l == '':
continue
if l.split(' ')[0] == 'Current':
continue
ip = ipaddr.IPv4Network(l)
if isinstance(line_num, int):
print str(line_num) + ' ',
line_num += 1
print 'permit ip any',
if ip.prefixlen < 32:
print str(ip.ip) + ' ' + str(ip.hostmask)
else:
print 'host ' + str(ip.ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment