Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. ####
  2. #
  3. # usage: python compareScans.py recentFile comparisonFile
  4. #        where recentFile = newest scan
  5. #              comparisonFile = old scan
  6. #
  7. ####
  8.  
  9. import re
  10. import sys
  11.  
  12. recentFile = open(sys.argv[1], 'r')
  13. comparisonFile = open(sys.argv[2], 'r')
  14.  
  15. matches = 0
  16. new = 0
  17.  
  18. matchList = []
  19. newList = []
  20.  
  21. def printList(theList):
  22.     for item in theList:
  23.         print item[0]
  24.  
  25. def returnIP(line):
  26.     line = re.findall( r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', line )
  27.     return line
  28.  
  29. def compareFiles():
  30.     global new, matches, newList, matchList
  31.     for line in recentFile:
  32.         if checkMatch(returnIP(line)):
  33.             matchList.append(returnIP(line))
  34.             matches += 1
  35.         else:
  36.             newList.append(returnIP(line))
  37.             new += 1
  38.  
  39. def checkMatch(ip):
  40.     global comparisonFile
  41.     for line in open(sys.argv[2], 'r'):
  42.         #print returnIP(line)
  43.         if ip == returnIP(line):
  44.             return True
  45.  
  46. compareFiles()
  47.  
  48.  
  49. print "Number of matches: %d" % matches
  50. printList(matchList)
  51. print "\r\n"
  52. print "Number of new items: %d" % new
  53. printList(newList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement