Skip to content

Instantly share code, notes, and snippets.

@tempookian
Last active March 12, 2023 18:27
Show Gist options
  • Save tempookian/66fc0c5ccc492f812a11c92572834b69 to your computer and use it in GitHub Desktop.
Save tempookian/66fc0c5ccc492f812a11c92572834b69 to your computer and use it in GitHub Desktop.
converts a list of cidrs stored in cidrs.txt into an ip list in ips.txt
import ipaddress
if __name__ == "__main__":
with open("cidrs.txt", "r") as infile:
cidrs = [l.strip() for l in infile.readlines() if l]
ips = [ip for cidr in cidrs for ip in list(
map(str, ipaddress.ip_network(cidr, strict=False)))]
with open("ips.txt", "w") as outfile:
outfile.write("\n".join(ips))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment