Paul Paul - 1 year ago 120
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:


Answer Source

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?
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download