Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####
- #
- # usage: python compareScans.py recentFile comparisonFile
- # where recentFile = newest scan
- # comparisonFile = old scan
- #
- ####
- import re
- import sys
- recentFile = open(sys.argv[1], 'r')
- comparisonFile = open(sys.argv[2], 'r')
- matches = 0
- new = 0
- matchList = []
- newList = []
- def printList(theList):
- for item in theList:
- print item[0]
- def returnIP(line):
- line = re.findall( r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', line )
- return line
- def compareFiles():
- global new, matches, newList, matchList
- for line in recentFile:
- if checkMatch(returnIP(line)):
- matchList.append(returnIP(line))
- matches += 1
- else:
- newList.append(returnIP(line))
- new += 1
- def checkMatch(ip):
- global comparisonFile
- for line in open(sys.argv[2], 'r'):
- #print returnIP(line)
- if ip == returnIP(line):
- return True
- compareFiles()
- print "Number of matches: %d" % matches
- printList(matchList)
- print "\r\n"
- print "Number of new items: %d" % new
- printList(newList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement