Last active
June 28, 2016 02:04
-
-
Save whoo/b9651f9954d15118689bc706a3c66984 to your computer and use it in GitHub Desktop.
Find Ip into subnet
This file contains hidden or 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
192.168.1.1 | |
192.168.2.3 | |
192.168.2.130 |
This file contains hidden or 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
192.168.1.0/24 | |
192.168.2.0/25 | |
192.168.4.0/28 |
This file contains hidden or 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 | |
import ipaddress | |
### read ip from ip.txt | |
### check if there is a match in subnet files | |
ipfile=open("ip.txt") | |
for ip in [line[:-1] for line in ipfile]: | |
found=0 | |
f=open("subnet.txt") | |
for a in [line[:-1] for line in f]: | |
if (ipaddress.ip_address(ip) in ipaddress.ip_network(a)): | |
print("%s Found in %s"%(ip,a)) | |
found=1 | |
break | |
if (found==0): | |
print("%s not found"%ip) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment