I'm new to Python.
The following line of code extract dst mac and src mac from a Ethernet packet.
dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
As we know, mac address is of 6-byte. What I want to archive is to compare if the first 5 bytes of dst/src mac addresses equal. How to write python code for that?
Use slice notation to extract subsequences from sequences like lists or strings. Comparing the first five bytes/characters of your dst
and src
strings is trivial:
dst[:5] == src[:5]
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.