Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Last active November 2, 2016 11:43
Show Gist options
  • Save pshchelo/a1e34b3518b2bd722074932ab10d30ba to your computer and use it in GitHub Desktop.
Save pshchelo/a1e34b3518b2bd722074932ab10d30ba to your computer and use it in GitHub Desktop.
all macs
#!/usr/bin/env python
"""Return all non-zero Ethernet (6 octets) MAC addresses"""
import itertools
import re
import netifaces
MAC_REGEXP = re.compile("^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$")
def all_mac_addrs(x):
return [i['addr'] for i in x[netifaces.AF_LINK]]
def is_nonzero_ethernet(x):
return (MAC_REGEXP.match(x) and x != ':'.join(['00']*6))
def get_all_eth_macs():
return filter(
is_nonzero_ethernet,
itertools.chain.from_iterable(
map(
all_mac_addrs,
map(
netifaces.ifaddresses,
netifaces.interfaces()
)
)
)
)
if __name__ == "__main__":
print(get_all_eth_macs())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment