use ipaddress is_loopback etc to do better forbidden ranges

closes #87
This commit is contained in:
jesopo 2019-09-30 15:12:01 +01:00
parent 8480309db2
commit b9c64b7cf1

View file

@ -301,5 +301,14 @@ def is_localhost(hostname: str) -> bool:
address = ipaddress.ip_address(link["addr"].split("%", 1)[0])
if address in ips:
return True
for ip in ips:
if ip.version == 6 and ip.ipv4_mapped:
ip = ip.ipv4_mapped
if (ip.is_loopback or
ip.is_link_local or
ip.is_multicast or
ip.is_private):
return True
return False