Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python3尝试处理多个不同的压缩pcap文件_Python_Scapy_Zipfile_Pcap_Pyshark - Fatal编程技术网

python3尝试处理多个不同的压缩pcap文件

python3尝试处理多个不同的压缩pcap文件,python,scapy,zipfile,pcap,pyshark,Python,Scapy,Zipfile,Pcap,Pyshark,我试图找到一个解决方案,在ZIP存档中工作(只需读取)PCAP/PCAP文件。 我不会将文件解压缩到磁盘,因为有1000个拉链,每个拉链里面都有一个pcap e、 G 我使用的是pyshark atm,但也可以使用dpkt,如果它与内存拉链一起工作的话。但是pyshark试图找到文件 >>> with ZipFile(pcaps_zip, "r") as z_in: ... for pcap in z_in.namelist():

我试图找到一个解决方案,在ZIP存档中工作(只需读取)PCAP/PCAP文件。 我不会将文件解压缩到磁盘,因为有1000个拉链,每个拉链里面都有一个pcap

e、 G

我使用的是pyshark atm,但也可以使用dpkt,如果它与内存拉链一起工作的话。但是pyshark试图找到文件

>>> with ZipFile(pcaps_zip, "r") as z_in: 
...     for pcap in z_in.namelist():                                                                                                                                                                                                                                          
...             pyshark.FileCapture(pcap)                                                                                                                                                                                             
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/local/lib/python3.6/site-packages/pyshark/capture/file_capture.py", line 48, in 
  __init__
    + str(self.input_filename)
FileNotFoundError: [Errno 2] No such file or directory: file1.pcap

 
>>将ZipFile(pcaps_-zip,“r”)作为z_插入:
...     对于z_in.namelist()中的pcap:
...             pyshark.FileCapture(pcap)
... 
回溯(最近一次呼叫最后一次):
文件“”,第3行,在
文件“/usr/local/lib/python3.6/site packages/pyshark/capture/File_capture.py”,第48行,在
__初始化__
+str(self.input_文件名)
FileNotFoundError:[Errno 2]没有这样的文件或目录:file1.pcap

希望我能理解你的问题。您正在尝试打开一个主zip存档,其中包含辅助存档,其中包含一个要使用pyshark处理的pcap文件

下面的代码以读取模式打开主zip存档以获取辅助存档名称,然后使用这些名称以读取模式打开每个辅助存档。在测试期间,我能够用pyshark读取每个pcap文件

我确实注意到,当处理像“\uu MACOSX/.\u 2.pcap”这样的文件名时,代码会抛出一个错误,所以我添加了错误处理。记录这些错误可能有助于故障排除

import pyshark
from zipfile import ZipFile

# primary zip archive that contains multiple zip archive
file_name = 'zipfile_test.zip'

# opening the primary zip archive in READ mode
with ZipFile(file_name, 'r') as z:
    # obtain the zip filenames within the primary archive 
    for zip_archive in z.namelist():
         # opening the secondary archive in READ mode
         with ZipFile(zip_archive, 'r') as za:
             try:
                # obtain the zip filenames within the secondary archive 
                for pcap_file in za.namelist():
                   capture = pyshark.FileCapture(pcap_file)
                   for packet in capture:
                     # do something with pcap packets

             except FileNotFoundError as e:
                 pass

          za.close()
     z.close()

希望我能理解你的问题。您正在尝试打开一个主zip存档,其中包含辅助存档,其中包含一个要使用pyshark处理的pcap文件

下面的代码以读取模式打开主zip存档以获取辅助存档名称,然后使用这些名称以读取模式打开每个辅助存档。在测试期间,我能够用pyshark读取每个pcap文件

我确实注意到,当处理像“\uu MACOSX/.\u 2.pcap”这样的文件名时,代码会抛出一个错误,所以我添加了错误处理。记录这些错误可能有助于故障排除

import pyshark
from zipfile import ZipFile

# primary zip archive that contains multiple zip archive
file_name = 'zipfile_test.zip'

# opening the primary zip archive in READ mode
with ZipFile(file_name, 'r') as z:
    # obtain the zip filenames within the primary archive 
    for zip_archive in z.namelist():
         # opening the secondary archive in READ mode
         with ZipFile(zip_archive, 'r') as za:
             try:
                # obtain the zip filenames within the secondary archive 
                for pcap_file in za.namelist():
                   capture = pyshark.FileCapture(pcap_file)
                   for packet in capture:
                     # do something with pcap packets

             except FileNotFoundError as e:
                 pass

          za.close()
     z.close()

这回答了你的问题吗?这回答了你的问题吗?