我正在尝试从
input.pcapng
文件读取数据包并修改数据包,如下所示。我想将这些数据包的列表保存在新的 pcap 文件中。请让我知道如何继续。
import pyshark
from scapy.utils import wrpcap
# open the input capture file
input_capture = pyshark.FileCapture('input.pcapng',keep_packets=True)
packets = []
# iterate through each packet in the input capture file
for packet in input_capture:
#some modification
if len(packet.layers) > 7:
count = 0
packet.layers.pop(0)
for i,layer in enumerate(packet.layers):
count += 1
if layer.layer_name == 'eth':
break
packet.layers = packet.layers[count-1:]
packets.append(packet)
wrpcap('output.pcap', packets)
input_capture.close()
(注:我尝试了wrpcap,Pcapwriter但未能成功。)
input_capture = pyshark.FileCapture('input.pcapng',output_file=keep_packets=True)
output_file可以保存捕获到的Packet