Advertisement
tuipveus

netaddress-check.py

Jan 4th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #!/usr/bin/python
  2. #http://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python
  3. #
  4. # Compares list of ip-addresses (murtautujat.txt) to the list of networks (verkot.txt) and lists ip's and networks which matches.
  5. #
  6. from netaddr import IPNetwork, IPAddress
  7.  
  8. m=0
  9. n=0
  10. file2 = open("verkot.txt", "r")
  11.  
  12. while 1:
  13.   m+=1
  14. #  print m
  15.   linen = file2.readline()
  16.   if not linen:
  17.     break
  18.   file = open("murtautujat.txt", "r")
  19.   while 1:
  20.     n+=1
  21.     line = file.readline()
  22.     if not line:
  23.       n=0
  24.       break
  25.     if IPAddress(line) in IPNetwork(linen):
  26.       print line, linen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement