0
  1. I am running live capture with pyshark module:

    filtered_cap = pyshark.LiveCapture(display_filter='TCPP', only_summaries=True)  
    packet_iter = filtered_cap.sniff_continuously()  
    for pkt in packet_iter:
        print(pkt)
    
  2. The display filter argument is incorrect e.g. 'TCPP'

  3. When running this code I have got exception that I cannot catch.
Exception ignored in: <function Capture.____del____ at ...> 
    ...  
pyshark.capture.capture.TSharkCrashException: TShark seems to have crashed (retcode: 2)

Any suggestion how to solve it?

Popa
  • 273
  • 1
  • 4
  • 13

1 Answers1

0

You likely solved this problem already, but this works for me.

import pyshark

def filter_tcp_live_packet_capture(network_interface):
    capture = pyshark.LiveCapture(interface=network_interface, display_filter='tcp', only_summaries=True)
    capture.sniff(timeout=50)
    for packet in capture.sniff_continuously(packet_count=5):
        try:
           print(packet)
        except AttributeError as e:
           pass

filter_tcp_live_packet_capture('en0')
Life is complex
  • 15,374
  • 5
  • 29
  • 58