Skip to content

Instantly share code, notes, and snippets.

@whoo
Last active June 28, 2016 02:04
Show Gist options
  • Save whoo/b9651f9954d15118689bc706a3c66984 to your computer and use it in GitHub Desktop.
Save whoo/b9651f9954d15118689bc706a3c66984 to your computer and use it in GitHub Desktop.
Find Ip into subnet
192.168.1.1
192.168.2.3
192.168.2.130
192.168.1.0/24
192.168.2.0/25
192.168.4.0/28
#!/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