diff --git a/host_agent.py b/host_agent.py index 5e104ed48..5278d09b5 100755 --- a/host_agent.py +++ b/host_agent.py @@ -5,6 +5,7 @@ __author__ = "Nash Kaminski" __license__ = "Dual License: GPLv2 and Commercial License" +import ipaddress import json import logging import netifaces @@ -25,20 +26,16 @@ def get_ip_addresses(): - addresses = [] - - for interface in netifaces.interfaces(): - if not interface.startswith(SUPPORTED_INTERFACES): - continue - - addrs = netifaces.ifaddresses(interface) - if netifaces.AF_INET in addrs or netifaces.AF_INET6 in addrs: - for ip in addrs.get(netifaces.AF_INET, []): - addresses.append(ip['addr']) - for ip in addrs.get(netifaces.AF_INET6, []): - addresses.append(ip['addr']) - - return addresses + return [ + ip['addr'] + for interface in netifaces.interfaces() + if interface.startswith(SUPPORTED_INTERFACES) + for ip in ( + netifaces.ifaddresses(interface).get(netifaces.AF_INET, []) + + netifaces.ifaddresses(interface).get(netifaces.AF_INET6, []) + ) + if not ipaddress.ip_address(ip['addr']).is_link_local + ] def set_ip_addresses():