3

I am looking to write a program to filter out and analyze PCAP file.

Here is my current code, which is throwing an error.

import pyshark
import asyncio

pcap_file = 'c:/sip.cap'

capture = pyshark.FileCapture(pcap_file,display_filter='sip contains factory')
for packet in capture:
    try:
        if hasattr(packet, 'sip'):
            field_names = packet.sip._all_fields
            field_values = packet.sip._all_fields.values()
            for field_name, field_value in zip(field_names, field_values):
                if field_name == 'sip.msg_hdr':
                    print(str(field_value.split('\\xd\\xa')))
                elif field_name == 'sip.msg_body':
                    print(field_value)
    except OSError:
        pass
    except asyncio.TimeoutError:
        pass

This error is being thrown:

Error on reading from the event loop self pipe
loop: <ProactorEventLoop running=True closed=False debug=False>
Traceback (most recent call last):
  File "C:\Users\rkaura\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 777, in _loop_self_reading
    f = self._proactor.recv(self._ssock, 4096)
  File "C:\Users\rkaura\AppData\Local\Programs\Python\Python38-32\lib\asyncio\windows_events.py", line 445, in recv
    self._register_with_iocp(conn)
  File "C:\Users\rkaura\AppData\Local\Programs\Python\Python38-32\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect
Life is complex
  • 15,374
  • 5
  • 29
  • 58

1 Answers1

0

Close the file capture object "capture".

The last line in the try block:

capture.close()
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103