python怎么导入数据包_python – Scapy:如何在现有数据包中插入新层(802.1q)?

为了找到答案,我看了一下

Scapy: Inserting a new layer and logging issues,这真的很有用,但包含了一些内容.

我根据引用的问题(add-dot1q_pcap.py)添加图层的解决方案:

import sys

from scapy.all import rdpcap, wrpcap, NoPayload, Ether, Dot1Q

# read all packets into buffer

# WARNING works only for small files

packets = []

for packet in rdpcap(sys.argv[1]):

# gets the first layer of the current packet

layer = packet.firstlayer()

# loop over the layers

while not isinstance(layer, NoPayload):

if 'chksum' in layer.default_fields:

del layer.chksum

if (type(layer) is Ether):

# adjust ether type

layer.type = 33024

# add 802.1q layer between Ether and IP

dot1q = Dot1Q(vlan=42)

dot1q.add_payload(layer.payload)

layer.remove_payload()

layer.add_payload(dot1q)

layer = dot1q

# advance to the next layer

layer = layer.payload

packets.append(packet)

wrpcap(sys.argv[2], packets)

该脚本添加了vlan id为42的vlan标记.

用法:./ add-div1q_pcap.py< source_file> < OUTPUT_FILE>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值