简体   繁体   中英

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?

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. 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.

The Ethertype field is set to a non-standard value and the frame content is not a published protocol.

I had same issue for LLDP (multicast), turns out that

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). In which the 01:80:c2:00:00:0e is the destination mac of LLDP packets.

See https://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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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