Skip to content

ipaddress: ip_address IPv6 has wrong properties for Shared Address Space (100.64.0.0) #107205

Open

Description

@cspencer404

Bug report

For IPv6, the ip_address and ip_network classes disagree on whether the "0:0:0:0:0:FFFF:6440:0000" address is_global and is_private. This behavior changed after python version 3.9, and the code below fails on 3.10+

The IPv6 address "0:0:0:0:0:FFFF:6440:0000" maps to IPv4 "100.64.0.0" using the ::ffff/96 rule from https://www.apnic.net/get-ip/faqs/what-is-an-ip-address/ipv6-address-types/

import ipaddress

ip_addr = ipaddress.ip_address("0:0:0:0:0:FFFF:6440:0000")
ip_net = ipaddress.ip_network("0:0:0:0:0:FFFF:6440:0000")

assert ip_addr.is_global == ip_net.is_global  # fails on py 3.10+
assert ip_addr.is_private == ip_net.is_private  # fails on py 3.10+
assert ip_addr.is_unspecified == ip_net.is_unspecified

print("ipv6 ok")

ip4_addr = ipaddress.ip_address("100.64.0.0")
ip4_net = ipaddress.ip_network("100.64.0.0")

assert ip4_addr.is_global == ip4_net.is_global
assert ip4_addr.is_private == ip4_net.is_private
assert ip4_addr.is_unspecified == ip4_net.is_unspecified

print("ipv4 ok")

Your environment

Mac OS 13.3.x

Python 3.8, 3.9, 3.10, 3.11

Reference for Shared Address Space https://www.rfc-editor.org/rfc/rfc6598.html

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions