0

I am trying to read packets from input.pcapng file and modified the packets as shown below. I want to save the list of these packets in new pcap file. Please let me know on how to proceed.

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()


(Note: I tried wrpcap , Pcapwriter but couldn't succeed.)

0 Answers0