Writing a pcap file

With the wrpcap() function, we can store the captured packets in a pcap file. Also, it is possible to write the packets to a pcap file with Scapy. To write the packets to a pcap file, we can use the wrpcap() method. In the following example, we are capturing tcp packets for FTP transmissions and saving this packets in a pcap file:

scapy > packets = sniff(filter='tcp port 21') scapy> file=wrpcap('<path_file.pcap>',packets)

Get Mastering Python for Networking and Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.