Skip to content

Instantly share code, notes, and snippets.

@bandrel
Created June 18, 2019 01:10
#!/usr/bin/env python3
'''
Script to expand CIDR notation to a list of IP addresses.
'''
import ipaddress
import sys
hosts = set()
subnets = str(sys.argv[1]).split(',')
for network in subnets:
try:
for host in ipaddress.IPv4Network(network).hosts():
hosts.add(host)
except ValueError:
for host in ipaddress.ip_interface(network).network.hosts():
hosts.add(host)
for host in hosts:
print(host)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment