I have a capture of some TCP packets in pcapng format and I’d like to open it in python to inspect the TCP payloads with address 192.168.1.198. I’ve only found this library: https://python-pcapng.readthedocs.io/en/latest/api/blocks.html but it does not support inspecting TCP payloads.
Is there an easy way?
Advertisement
Answer
You can use python-pcapng
package. First install python-pcapng package by following command.
JavaScript
x
2
1
pip install python-pcapng
2
Then use following sample code.
JavaScript
1
8
1
from pcapng import FileScanner
2
3
with open(r'C:UserszahangirDownloadsMDS19 Wireshark Log 08072021.pcapng', 'rb') as fp:
4
scanner = FileScanner(fp)
5
for block in scanner:
6
print(block)
7
print(block._raw) #byte type raw data
8
Above code worked for me.
Reference: https://pypi.org/project/python-pcapng/