As is known, pyshark is a wrapper for tshark. With large volumes of traffic, part of the packets are lost due to the limitations of the buffer size (tshark has 2 MB by default)
My idea is as follows: I want to run tshark with a buffer size like 20MB and pipe the output to my Python script. In this case, instead of LiveCapture, I use PipeCapture as follow:
import pyshark
import pandas as pd
import os
r, w = os.pipe()
pid = os.fork()
r = os.fdopen(r)
capture = pyshark.PipeCapture(pipe=r, bpf_filter='udp port 5060')
for packet in capture.sniff_continuously():
print(packet)
And i got error:
AttributeError: module 'pyshark' has no attribute 'PipeCapture' .
I checked source code of pyshark here: https://github.com/KimiNewt/pyshark/blob/master/src/pyshark/capture/pipe_capture.py
Whats wrong?
UPDATE:
As @maxkanthauer recommended I do:
import pyshark
import pandas as pd
import sys
from pyshark.capture.pipe_capture import PipeCapture
r = sys.stdin
while True:
capture = PipeCapture(pipe=r)
print(capture)
and start my script :
tcpdump -l port 5060 -i etho | python pyshark_test.py
Although i sure that there are many packets the output is :
<PipeCapture (0 packets)>
<PipeCapture (0 packets)>
<PipeCapture (0 packets)>