ipaddress considers some not globally reachable addresses global and vice versa · Issue #113171 · python/cpython (original) (raw)

Bug report

Bug description:

Judging by what the is_private and is_global implementations in the ipaddress module do[1], everything that IANA special-purpose address registries[2][3] considers globally reachable should result in is_global == True, the rest should be is_global = True.

is_private is almost always the opposite of is_global (100.64.0.0/10 is special).

The problem is the ranges present in the code (in the _private_networks variables) are not quite right:

This is what I have right now and I'll submit that as a PR:

diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 5b5520b92bde..3ee565bcd30b 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1558,13 +1558,18 @@ class _IPv4Constants:

 _public_network = IPv4Network('100.64.0.0/10')

@@ -2306,15 +2311,31 @@ class _IPv6Constants:

 _multicast_network = IPv6Network('ff00::/8')

[1] And which should really be documented per #65056 – a separate issue though
[2] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
[3] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs