list - Encountering IndexError when file parsing with Python -


i have file containing previous tcpdump, file has lines in format:

17:20:03.867998 ip 23.222.75.204.443 > 192.168.0.15.51773: flags [.], ack 518, win 916, options [nop,nop,ts val 303057114 ecr 43022775], length 0 17:20:03.870231 ip 209.148.192.43.80 > 192.168.0.15.60174: flags [.], seq 1:1449, ack 511, win 486, options [nop,nop,ts val 1840008838 ecr 43022779], length 1448 

my function extracts specific strings in each line (the source , destination addresses) , prints them. strange thing works (everything should print does) in end error.

here's code:

def parse_file() :    try :       file_object = open("tcp_dump","r")        x in file_object.readlines() :          source_ip=x.split("ip ")[1].split(" >")[0]          dest_ip=x.split("> ")[1].split(": flags")[0]          print(source_ip)          print(dest_ip)        file_object.close()     except ioerror :       print("the specified file not found/accessed")   parse_file() 

here's output:

23.222.75.204.443 192.168.0.15.51773 209.148.192.43.80 192.168.0.15.60174 traceback (most recent call last):   file "./test", line 26, in <module>     parse_file()   file "./test", line 15, in parse_file     source_ip=x.split("ip ")[1].split(" >")[0] indexerror: list index out of range 


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -