Created
September 22, 2012 05:58
-
-
Save jeremyvisser/3765294 to your computer and use it in GitHub Desktop.
Internode to Cisco ACL
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
#!/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