Created
June 18, 2019 01:10
-
-
Save bandrel/e84c98c357dea4e80d9039c66647ba33 to your computer and use it in GitHub Desktop.
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 | |
''' | |
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