Created
January 10, 2017 14:43
-
-
Save sorz/06287f7394166a4529290fcc22a0abfb to your computer and use it in GitHub Desktop.
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/env python3 | |
| import sys | |
| import math | |
| from ipaddress import IPv4Network | |
| def main(): | |
| for line in sys.stdin: | |
| if 'CN' not in line or 'ipv4' not in line: | |
| continue | |
| cols = line.strip().split('|') | |
| ip, num = cols[3:5] | |
| prefixlen = 32 - int(math.log(int(num), 2)) | |
| ipnet = IPv4Network('%s/%s' % (ip, prefixlen)) | |
| #print(ipnet) | |
| #print(ipnet.with_netmask) | |
| print('add cnnet %s' % ipnet.with_prefixlen) | |
| #net, mask = ipnet.with_netmask.split('/') | |
| #print("add %s mask %s default METRIC default IF default" \ | |
| # % (net, mask)) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment