Add IPv6 support to StatusServer and related classes. #119

Open
moodyjon wants to merge 8 commits from moodyjon/ipv6 into master
Showing only changes of commit d495ce9f0a - Show all commits

View file

@ -610,11 +610,13 @@ IPV4_TO_6_RELAY_SUBNET = ipaddress.ip_network('192.88.99.0/24')
def is_valid_public_ipv4(address, allow_localhost: bool = False, allow_lan: bool = False): def is_valid_public_ipv4(address, allow_localhost: bool = False, allow_lan: bool = False):
try: try:
parsed_ip = ipaddress.ip_address(address) parsed_ip = ipaddress.ip_address(address)
if parsed_ip.version != 4:
return False
if parsed_ip.is_loopback: if parsed_ip.is_loopback:
return allow_localhost return allow_localhost
if parsed_ip.is_private: if parsed_ip.is_private:
return allow_lan return allow_lan
if any((parsed_ip.version != 4, parsed_ip.is_unspecified, parsed_ip.is_link_local, parsed_ip.is_loopback, if any((parsed_ip.is_unspecified, parsed_ip.is_link_local, parsed_ip.is_loopback,
parsed_ip.is_multicast, parsed_ip.is_reserved, parsed_ip.is_private)): parsed_ip.is_multicast, parsed_ip.is_reserved, parsed_ip.is_private)):
return False return False
else: else:
@ -626,14 +628,15 @@ def is_valid_public_ipv4(address, allow_localhost: bool = False, allow_lan: bool
def is_valid_public_ipv6(address, allow_localhost: bool = False, allow_lan: bool = False): def is_valid_public_ipv6(address, allow_localhost: bool = False, allow_lan: bool = False):
try: try:
parsed_ip = ipaddress.ip_address(address) parsed_ip = ipaddress.ip_address(address)
if parsed_ip.version != 6:
return False
if parsed_ip.is_loopback: if parsed_ip.is_loopback:
return allow_localhost return allow_localhost
if parsed_ip.is_private: if parsed_ip.is_private:
return allow_lan return allow_lan
return not any((parsed_ip.version != 6, parsed_ip.is_unspecified, return not any((parsed_ip.is_unspecified, parsed_ip.is_link_local, parsed_ip.is_loopback,
parsed_ip.is_link_local, parsed_ip.is_loopback, parsed_ip.is_multicast, parsed_ip.is_reserved, parsed_ip.is_private,
parsed_ip.is_multicast, parsed_ip.is_reserved, parsed_ip.ipv4_mapped))
parsed_ip.is_private, parsed_ip.ipv4_mapped))
except (ipaddress.AddressValueError, ValueError): except (ipaddress.AddressValueError, ValueError):
return False return False