Paul Paul - 5 months ago 32
Python Question

Is there a library function to check if a MAC address is multicast?

I know that I can use the

module to check if an IP address is multicast like so:


Before I go ahead and write my own, is there a comparable function for the various formats of MAC addresses?

For instance:



For completeness: A "function" to check this is as easy as

>>> mac = netaddr.EUI('0123.4567.89ab')
>>> mac_is_multicast = bool(mac.words[0] & 0b01)  # Is LSB set?

Similarly, you can check if a MAC address is locally administered with

>>> mac = netaddr.EUI('0123.4567.89ab')
>>> mac_is_locally_administered = bool(mac.words[0] & 0b10)  # Is 2nd LSB set?