- for line in output.split('\n'):
- line = str(line, 'ascii')
- ip = string_utils.extract_ip_v4(line)
- mac = string_utils.extract_mac_address(line)
+ except Exception as e:
+ logger.exception(e)
+ return
+ for line in output.split('\n'):
+ ip = string_utils.extract_ip_v4(line)
+ mac = string_utils.extract_mac_address(line)
+ if (
+ ip is not None
+ and mac is not None
+ and mac != 'UNKNOWN'
+ and ip != 'UNKNOWN'
+ ):
+ mac = mac.lower()
+ logger.debug(f'ARPER: {mac} => {ip}')
+ self.state[mac] = ip
+
+ def update_from_arp(self):
+ try:
+ output = exec_utils.cmd('/usr/sbin/arp -a', timeout_seconds=10.0)
+ except Exception as e:
+ logger.exception(e)
+ return
+ for line in output.split('\n'):
+ ip = string_utils.extract_ip_v4(line)
+ mac = string_utils.extract_mac_address(line)
+ if (
+ ip is not None
+ and mac is not None
+ and mac != 'UNKNOWN'
+ and ip != 'UNKNOWN'
+ ):