Last active
November 2, 2016 11:43
-
-
Save pshchelo/a1e34b3518b2bd722074932ab10d30ba to your computer and use it in GitHub Desktop.
all macs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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