I've got a python script that launches tshark and then uses tcpreplay to inject packets onto a small network. After tshark stops capturing and writes a pcap to disk, I attempt to use another tshark call to translate that capture to text for parsing. This last bit doesn't work. I see 'tshark: Unrecognized libpcap format' on screen. Code looks like this:
The calls themselves appear correct. Tshark captures, tcpreplay replays ‘replay.pcap’, tshark writes ‘result.pcap’ to file, and this file contains what it should. ‘result.txt’ is empty however. If (just to see) I replace ‘result.pcap’ with ‘replay.pcap’ in the translate call, there is no error, and ‘result.txt’ has what I expect. If I comment out the replay launch (with ‘result.pcap’ in the translate call), there is again no error, and ‘result.txt’ has what I would expect. It really looks like the issue is with running tshark, then tcpreplay, and finally tshark to translate to text–all those things together. I would be happy to have the first tshark call write the ‘result.txt’ file directly rather than using a second call to write it out, but I haven’t had luck with that either. I can open ‘result.pcap’ with Wireshark and export the file to text without any issues. FYI ‘replay.pcap’ is generated using text2pcap, from this:
What am I doing wrong? asked 25 Sep ‘13, 11:23 ozymandias |
One Answer:
O.K. capinfos shows it's a pcap-ng file.
well, the error must be related to the way you run tshark. Why do you call it this way
and not this way:
Regards answered 25 Sep '13, 13:32 Kurt Knochner ♦ edited 25 Sep '13, 13:34 That works! I did it the way I did out of ignorance, which thanks to your answer, is a little less than it was before. Thanks much. (25 Sep '13, 14:04) ozymandias good. Hint: If a supplied answer resolves your question can you please "accept" it by clicking the checkmark icon next to it. This highlights good answers for the benefit of subsequent users with the same or similar questions. (25 Sep '13, 14:06) Kurt Knochner ♦ |
what is the output of the following commands:
That was capinfos above.
file result.pcap gives: result.pcap pcap-ng capture file - version 1.0
od -x result.pcap | head 20 (20 had to be left off)
0000000 0d0a 0a0d 0050 0000 3c4d 1a2b 0001 0000
0000020 ffff ffff ffff ffff 0003 0015 694c 756e
0000040 2078 2e33 2e32 2d30 2d34 3836 2d36 6170
0000060 0065 0000 0004 000d 7544 706d 6163 2070
0000100 2e31 2e38 0032 0000 0000 0000 0050 0000
0000120 0001 0000 0044 0000 0001 0000 ffff 0000
0000140 0002 0004 7465 3068 0009 0001 0006 0000
0000160 000c 0015 694c 756e 2078 2e33 2e32 2d30
0000200 2d34 3836 2d36 6170 0065 0000 0000 0000
0000220 0044 0000 0006 0000 005c 0000 0000 0000