pyshark - data from TCP packet

Cru Jones picture Cru Jones · May 9, 2015 · Viewed 12.2k times · Source

Is there anyway to get the payload of a TCP packet using pyshark?

I am trying to compare the data sections of different packets across multiple TCP streams but I can't find a way to get at the data of the packet. pkt['tcp'].data does not seem to exist.

Answer

Chandan picture Chandan · Oct 4, 2015

If you are using a .pcap file, once you have read the file using

cap = pyshark.FileCapture('vox.pcap')

and say, you want to read the data of the 2nd packet, and you are sure such a field exists, try:

pkt = cap[1]
print pkt.tcp.data

To see the options available for pkt.tcp, use:

dir(pkt.tcp)

It will return all the available options for pkt.tcp