def _CreateInterfaceMapNetifaces(self):
    """Generate a dictionary mapping MAC address to Ethernet interfaces.

    Returns:
      dict, string MAC addresses mapped to the string network interface name.
    """

    interfaces = {}
    for interface in netifaces.interfaces():
      af_link = netifaces.ifaddresses(interface).get(netifaces.AF_LINK, [])
      mac_address = next(iter(af_link), {}).get('addr', '')
      # In some systems this field can come with an empty string or with the
      # name of the interface when there is no MAC address associated with it.
      # Check the regex to be sure.
      if MAC_REGEX.match(mac_address):
        interfaces[mac_address] = interface
      else:
        message = 'Unable to determine MAC address for %s.'
        self.logger.warning(message, interface)
    return interfaces
def _CreateInterfaceMapNetifaces ( self ) : interfaces = { } for interface in netifaces . interfaces ( ) : af_link = netifaces . ifaddresses ( interface ) . get ( netifaces . AF_LINK , [ ] ) mac_address = next ( iter ( af_link ) , { } ) . get ( 'addr' , '' ) if MAC_REGEX . match ( mac_address ) : interfaces [ mac_address ] = interface else : message = 'Unable to determine MAC address for %s.' self . logger . warning ( message , interface ) return interfaces
Generate a dictionary mapping MAC address to Ethernet interfaces.

    Returns:
      dict, string MAC addresses mapped to the string network interface name.