Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #http://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python
- #
- # Compares list of ip-addresses (murtautujat.txt) to the list of networks (verkot.txt) and lists ip's and networks which matches.
- #
- from netaddr import IPNetwork, IPAddress
- m=0
- n=0
- file2 = open("verkot.txt", "r")
- while 1:
- m+=1
- # print m
- linen = file2.readline()
- if not linen:
- break
- file = open("murtautujat.txt", "r")
- while 1:
- n+=1
- line = file.readline()
- if not line:
- n=0
- break
- if IPAddress(line) in IPNetwork(linen):
- print line, linen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement