我一直在尝试Scapy,但是文档太稀疏了,我无法让它在简单的编辑中发挥出色。
基本上,我正在寻找一个简单的Python解决方案来从.pcap中获取每个数据包,读取/修改一些数据/删除数据包并将其保存为.pcap。
例如:
给定sACN数据包,我需要读取/修改优先级八位字节(108)和Universe八位字节(113-114)并再次保存。
谢谢!
答案 0 :(得分:2)
处理" .pcap"您需要导入scapy
的文件' PcapWriter '来自' scapy.utils '。以下示例演示了如何处理" .pcap" scapy
的文件:
#!/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)
现在,如果您查看" .pcap"使用wireshark
的文件您将看到数据包已成功修改: