Created
June 20, 2014 06:18
-
-
Save heyalexej/7326e28585a54c92f8bf to your computer and use it in GitHub Desktop.
Quick and dirty solution to translate IPv4 and IPv6 CIDR blocks into a list of IPs for further digestion.
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 python3 | |
# Translates IPv4/6 CIDR blocks into a list of IPs and writes | |
# them into a text file. Requires netaddr (pip install netaddr). | |
import netaddr | |
ip_list = netaddr.IPNetwork('192.168.1.0/21') | |
with open('ips-from-cidr.txt', 'w') as f: | |
for ip in ip_list: | |
f.write(str(ip) + '\n') | |
#print(str(ip)) # additionally print to stdout if you like | |
f.close() | |
print('\nGenerated "{0:s}" with {1:d} IPs.\n'.format((f.name), | |
len(ip_list))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment