Adds the `IPv4Address.ipv6_mapped` property.
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
``True`` if the address is reserved for link-local usage. See
:RFC:`3927`.
+ .. attribute:: ipv6_mapped
+
+ :class:`IPv4Address` object representing the IPv4-mapped IPv6 address. See :RFC:`4291`.
+
+ .. versionadded:: 3.13
+
+
.. _iana-ipv4-special-registry: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
.. _iana-ipv6-special-registry: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
built on debug mode <debug-build>`.
(Contributed by Victor Stinner in :gh:`62948`.)
+ipaddress
+---------
+
+* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which returns the IPv4-mapped IPv6 address.
+ (Contributed by Charles Machalow in :gh:`109466`.)
+
opcode
------
"""
return self in self._constants._linklocal_network
+ @property
+ def ipv6_mapped(self):
+ """Return the IPv4-mapped IPv6 address.
+
+ Returns:
+ The IPv4-mapped IPv6 address per RFC 4291.
+
+ """
+ return IPv6Address(f'::ffff:{self}')
+
class IPv4Interface(IPv4Address):
def test_weakref(self):
weakref.ref(self.factory('192.0.2.1'))
+ def test_ipv6_mapped(self):
+ self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped,
+ ipaddress.IPv6Address('::ffff:192.168.1.1'))
+ self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped,
+ ipaddress.IPv6Address('::ffff:c0a8:101'))
+ self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped.ipv4_mapped,
+ ipaddress.IPv4Address('192.168.1.1'))
+
class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6):
factory = ipaddress.IPv6Address
--- /dev/null
+Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which retuns the IPv4-mapped IPv6 address.\r