Skip to content

Commit f492f39

Browse files
authored
Add IPv4-IPv6 Translation
This does not handle translation with a Network-Specific Prefix, which must be known beforehand when embedding IPv4 addresses with RFC 6052. https://www.rfc-editor.org/rfc/rfc6052.html#section-2.2
1 parent 264c00a commit f492f39

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Lib/ipaddress.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,19 @@ def sixtofour(self):
20942094
return None
20952095
return IPv4Address((self._ip >> 80) & 0xFFFFFFFF)
20962096

2097+
@property
2098+
def ipv4_translation(self):
2099+
"""Return the IPv4/IPv6 Translation embedded address.
2100+
2101+
Returns:
2102+
The IPv4/IPv6 Translation embedded address if present or None
2103+
if the address doesn't appear to contain a translation address.
2104+
2105+
"""
2106+
if (self._ip >> 96) != 0x64FF9B:
2107+
return None
2108+
return IPv4Address(self._ip & 0xFFFFFFFF)
2109+
20972110

20982111
class IPv6Interface(IPv6Address):
20992112

0 commit comments

Comments
 (0)