简体   繁体   English

接收多播以太网帧

[英]Receiving multicast Ethernet frames

How can I listen for raw Ethernet frames addressed to a multicast MAC address (eg 77:77:77:77:77:77 ) in Python?如何在 Python 中侦听寻址到多播 MAC 地址(例如77:77:77:77:77:77 )的原始以太网帧?

I'm listening for raw frames like this:我正在听这样的原始帧:

s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_TYPE))
s.bind(("eth0", 0))
s.recv(2048)

I can see the frames arriving on eth0 using tcpdump but the above code does not see them.我可以使用tcpdump看到到达eth0的帧,但上面的代码没有看到它们。 I think I need to tell the kernel that I'm interested in the multicast MAC address they're sent to but don't know how.我想我需要告诉 kernel 我对它们发送到的多播 MAC 地址感兴趣,但不知道如何发送。

The Ethertype field is set to a non-standard value and the frame content is not a published protocol. Ethertype 字段设置为非标准值,并且帧内容不是已发布的协议。

I had same issue for LLDP (multicast), turns out that我对 LLDP(多播)有同样的问题,结果证明

ip link set eth0 allmulticast on

or或者

ip link set eth0 promisc on

both works for me.两者都对我有用。

EDIT: found another safe way:编辑:找到另一种安全的方式:

ip maddress add 01:80:c2:00:00:0e dev eth0

for my case (LLDP).对于我的情况(LLDP)。 In which the 01:80:c2:00:00:0e is the destination mac of LLDP packets.其中01:80:c2:00:00:0e是LLDP报文的目的mac。

See https://github.com/jjqq2013/simple-lldp-capture-python-script/blob/main/lldp.shhttps://github.com/jjqq2013/simple-lldp-capture-python-script/blob/main/lldp.sh

for your case it should be:对于您的情况,它应该是:

ip maddress add 77:77:77:77:77:77 dev eth0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM