Created
May 30, 2019 03:44
-
-
Save wafer-li/bcac22f84fe1faff3ce9a23edd5eb59c to your computer and use it in GitHub Desktop.
CIDR to IP range
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
import argparse | |
from netaddr import IPNetwork | |
arg_parser = argparse.ArgumentParser() | |
arg_parser.add_argument('filename', help='The filename of the file you need to convert') | |
args = arg_parser.parse_args() | |
src_filename = args.filename | |
output_filename = 'ip-range.txt' | |
with open(output_filename, 'w') as output: | |
with open(src_filename, 'r') as f: | |
for line in f: | |
network = list(IPNetwork(line)) | |
start = network[0] | |
end = network[-1] | |
output.write(str(start)+'-'+str(end)+'\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Require dependency: