Support interfaces that don't have AF_INET and/or AF_INET6
This commit is contained in:
parent
ce1bbb7abe
commit
1240b154cb
1 changed files with 4 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue