scapy icon indicating copy to clipboard operation
scapy copied to clipboard

Pcapreader() does not work with PosixPath from Python's pathlib

Open tanwirahmad opened this issue 2 years ago • 0 comments

Brief description

Pcapreader() is expecting the fname parameter to be in str. However, after the release of pathlib in Python 3.4, file paths can exist as PosixPath or WindowsPath instances on Unix or Windows OS, respectively.

Scapy version

2.4.5

Python version

3.8

Operating system

Ubuntu 20.04

Additional environment information

No response

How to reproduce

from pathlib import Path
from scapy.all import *

pcap_file = Path('/home/my/network_traffic.pcap')
cap = PcapReader(pcap_file)

Actual result

Traceback (most recent call last):
  File "preprocess_scapy.py", line 4
    cap = PcapReader(pcap_file)
  File "/home/my/.venv/pcap/lib/python3.8/site-packages/scapy/utils.py", line 1151, in __call__
    filename, fdesc, magic = cls.open(filename)
  File "/home/my/.venv/pcap/lib/python3.8/site-packages/scapy/utils.py", line 1189, in open
    magic = fdesc.read(4)
AttributeError: 'PosixPath' object has no attribute 'read'

Expected result

No response

Related resources

No response

tanwirahmad avatar May 04 '22 15:05 tanwirahmad