Created
October 6, 2016 16:29
-
-
Save konradkonrad/11eb5b716ad44a8a9b929f694aca2d79 to your computer and use it in GitHub Desktop.
check list of ips against list of networks/netmasks
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 python | |
import sys | |
import ipaddress | |
if __name__ == "__main__": | |
if len(sys.argv) < 3: | |
print("Usage:\n\t%s ips_file networks_file" % sys.argv[0]) | |
sys.exit(0) | |
ips_fn = sys.argv[1] | |
networks_fn = sys.argv[2] | |
with open(ips_fn) as f: | |
ips = f.readlines() | |
ips = [ip.strip('\n') for ip in ips] | |
ips = [ipaddress.IPv4Address(unicode(ip)) for ip in ips] | |
with open(networks_fn) as f: | |
networks = f.readlines() | |
networks = [net.strip('\n') for net in networks] | |
networks = [ipaddress.IPv4Network(unicode(net)) for net in networks] | |
for ip in ips: | |
if not any(ip in net for net in networks): | |
print("NOT covered %s" % ip) | |
else: | |
print("covered: %s" % ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment