首页 > 解决方案 > 使用 scapy 生成 LACP 流量

问题描述

我需要使用 scapy 生成 STP 和 LACP 流量。我已经为 STP 做到了:

from scapy.all import STP
import scapy
from scapy.all import *
data='test'
a=Dot3(dst="01:00:0c:cc:cc:cd", src="08:17:35:51:29:2e")/LLC(dsap=0xaa, ssap=0xaa, ctrl=3)/SNAP(OUI=0x0c, code=0x010b)/STP(rootid=8406, portid=0x802e, pathcost=19, rootmac="2c:33:11:53:85:80",bridgeid=32982, bridgemac="08:17:35:51:29:00", bpdutype=128)/data
sendp(a,iface="eth2", count=200)

但是我被 LACP 流量的生成阻止了,我试图关注scapy.contrib.lacp但我不明白如何使用它

标签: pythonpython-3.xgeneratorscapylacp

解决方案


在生成中,您应该让 scapy 放置链接层的协议类型。


import scapy.all as scapy
from scapy.layers.inet import Ether, Dot3
from scapy.contrib.lacp import SlowProtocol, LACP
from scapy.layers.l2 import LLC, SNAP, STP


data='test'
pkt = Dot3(dst="01:00:0c:cc:cc:cd", src="08:17:35:51:29:2e") \
    / LLC(dsap=0xaa, ssap=0xaa, ctrl=3) \
    / SNAP(OUI=0x0c, code=0x010b) \
    / STP(rootid=8406, portid=0x802e, pathcost=19, rootmac="2c:33:11:53:85:80",bridgeid=32982, bridgemac="08:17:35:51:29:00", bpdutype=128) \
    / data
pkt.show2()
sendp(pkt, iface="eth2", count=200)

pkt = Ether() / SlowProtocol() / LACP()
pkt.show2()
sendp(pkt, iface="eth2", count=200)


推荐阅读