Skip to content

Instantly share code, notes, and snippets.

@bandrel
Created June 18, 2019 01:10
Show Gist options
  • Save bandrel/e84c98c357dea4e80d9039c66647ba33 to your computer and use it in GitHub Desktop.
Save bandrel/e84c98c357dea4e80d9039c66647ba33 to your computer and use it in GitHub Desktop.
#!/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