What my code is suppose to do is take in user input search terms then iterate through a tcp dump file and find every instance of that term by packet. The src IP acts as the header to each packet in my output.
So I am having an issue with the fileIn being seemingly erased when it iterates through the first term. So when the program goes to look at the second user input search term it obviously can't find anything. Here is what I have:
import re
searchTerms = []
fileIn = open('ascii_dump.txt', 'r')
while True:
userTerm = input("Enter the search terms (End to stop): ")
if userTerm == 'End':
break
else:
searchTerms.append(userTerm)
ipPattern = re.compile(r'((?:\d{1,3}\.){3}\d{1,3})')
x = 0
while True:
print("Search Term is:", searchTerms[x])
for line in fileIn:
ipMatch = ipPattern.search(line)
userPattern = re.compile(searchTerms[x])
userMatch = userPattern.search(line)
if ipMatch is not None:
print(ipMatch.group())
if userMatch is not None:
print(userMatch.group())
x += 1
if x >= len(searchTerms):
break