Support interfaces that don't have AF_INET and/or AF_INET6

This commit is contained in:
jesopo 2019-04-25 17:48:51 +01:00
parent ce1bbb7abe
commit 1240b154cb

View file

@ -110,8 +110,11 @@ def is_localhost(hostname: str) -> bool:
for interface in netifaces.interfaces(): for interface in netifaces.interfaces():
links = netifaces.ifaddresses(interface) links = netifaces.ifaddresses(interface)
for link in links[netifaces.AF_INET]+links[netifaces.AF_INET6]:
for link in links.get(netifaces.AF_INET, []
)+links.get(netifaces.AF_INET6, [])
address = ipaddress.ip_address(link["addr"].split("%", 1)[0]) address = ipaddress.ip_address(link["addr"].split("%", 1)[0])
if address in ips: if address in ips:
return True return True
return False return False