Guest User

Untitled

a guest
Aug 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import re # import python regexp library
  2.  
  3. with open("dumpfile.txt", "r") as file: # open the file
  4. lines = file.readlines() # read lines from file
  5.  
  6. # at first I thought you want to parse even more parameters
  7.  
  8. # regular expression
  9. pattern = "(?P<date>.*) IP (?P<senderIP>[\.\d]*)\.(?P<senderPort>\d*) \> (?P<reciverIP>[\.\d]*)\.(?P<recieverPort>\d*): Flags \[(?P<flags>.*)\],.*"
  10.  
  11. Pkts = {} # {uniqueIP:number of packets associated}
  12.  
  13. for line in lines: # go trought every line and
  14. result = re.match(pattern, line) # match line for every line
  15.  
  16. if not Pkts.has_key(result.group("senderIP")): # if this ip was not used then we will set the result to 1
  17. Pkts[result.group("senderIP")] = 1
  18. else: # in other case we will just add 1
  19. Pkts[result.group("senderIP")] += 1
  20.  
  21. if not Pkts.has_key(result.group("reciverIP")): # same as previous only this time we check for receiver ip adress
  22. Pkts[result.group("reciverIP")] = 1
  23. else:
  24. Pkts[result.group("reciverIP")] += 1
  25.  
  26. for ip in Pkts.keys():
  27. print ip, "Number of packets recived/sent:", Pkts[ip] # just printing the result
Add Comment
Please, Sign In to add comment