Last active
March 12, 2023 18:27
-
-
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
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
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