Joshua Rogers' Scribbles

Python's ipaddress is_global and is_private

I found this interesting.

Python’s ipaddress has is_global and is_private, which can be used to determine whether a network address is internet-routable or internal/private-only respectively.

These change over time. What surprised me is that they were changed in patch releases:

  1. CVE-2024-4032 (gh-113171): the module’s lists were out of date with IANA’s special-purpose address registries. It was fixed in 3.11.10 and 3.12.4.
  2. gh-122792: IPv4-mapped IPv6 addresses (::ffff:a.b.c.d) now take their properties from the embedded IPv4 address.
  3. gh-124217: 3fff::/20, the new IPv6 documentation prefix from RFC 9637, is no longer global.

ipaddress.ip_address(addr).is_global across a couple releases:

Address 3.11.9, 3.12.3 3.11.10, 3.12.4–3.12.6, 3.13.0 3.11.11, 3.12.7, 3.13.1+
192.0.0.8 True False False
64:ff9b:1::1 True False False
2002::1 True False False
2001:1::1 False True True
3fff::1 True True False

::ffff:100.100.100.100 (a Tailscale-style address, mapped) is global on 3.13.0, and not on 3.13.1.

Distributions backported the CVE fix into their own builds, but not always, so two OS’ that both say “Python 3.11” disagree.

In reality, probably none of this matters. But perhaps you could just parse IANA’s IPv4 and IPv6 registries yourself.