this is my first question asked here at stackoverflow and am really looking forward to being part of this community. I am new to program and python was the most recommended first program by many people.
Anyways. I have a log file which looks like this:
"No.","Time","Source","Destination","Protocol","Info"
"1","0.000000","120.107.103.180","172.16.112.50","TELNET","Telnet Data ..."
"2","0.000426","172.16.112.50","172.16.113.168","TELNET","Telnet Data ..."
"3","0.019849","172.16.113.168","172.16.112.50","TCP","21582 > telnet [ACK]"
"4","0.530125","172.16.113.168","172.16.112.50","TELNET","Telnet Data ..."
"5","0.530634","172.16.112.50","172.16.113.168","TELNET","Telnet Data ..."
And I wanted to parse the log file using Python to make it look like this as the result:
From IP 135.13.216.191 Protocol Count:
(IMF 1)
(SMTP 38)
(TCP 24) (Total: 63)
I would really like some help on what path to take to tackle this problem should I use lists and loop through it or dictionaries/tuples?
Thanks in advance for your help!
First you’ll want to read in the text file
Set up a dictionary to hold your results
Now iterate over your data, one line at a time, and record the protocol in the dictionary
Once you’ve counted everything, just iterate over your counts and print out the results