あなたは 'scapy.utils' から 'PcapWriter' をインポートする必要があります。あなたはパケットが正常に変更されていることがわかりますwireshark
で「.pcap」ファイルを表示する場合は今
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from scapy.all import *
# to process .pcap files we need to
# import 'PcapWriter' from 'scapy.utils'
from scapy.utils import PcapWriter
# initialize a 'net_old.pcap' file
old_cap = PcapWriter("net_old.pcap", append=True, sync=True)
# create a simple packet
packet = IP(dst = "www.google.com")/ICMP()/"hi"
# create a pcap with 5 such packets
for _ in range(5): old_cap.write(packet)
# now read the packets from 'net.pcap'
packets = rdpcap('net_old.pcap')
new_cap = PcapWriter("net_new.pcap", append=True)
# and modify each packet
for p in packets:
# modify any packet field, e.g. IP's dst
p[IP].dst = '8.8.8.8'
# write new packets in the new pcap file
new_cap.write(p)
::次の例では、scapy
と「.pcap」ファイルを処理する方法を示し
![enter image description here](https://i.stack.imgur.com/BY1Bv.png)
![enter image description here](https://i.stack.imgur.com/FUBD5.png)
を感謝し、フィールドに建設を必要とせずに、各パケット内のデータの単一オクテットを変更する簡単な方法はありますか? –
'packet.show2()'でパケットのフィールドを表示し、変更するフィールドを選択できます。別の方法は、生のパケット(バイト)を処理することです - パケットを 'str(packet)'を使うことができるバイトとして(python 2.x上で) – coder