Python Glossary Русский

Python 3.3+ipaddressterm

ipaddress.IPv6Address

addresses

The IPv6 address class: it holds a 128-bit address, prints in compressed form and gives the full form via .exploded.

Syntax

ipaddress.IPv6Address(address)

The same address has many spellings ('2001:0db8:0000::0001' and '2001:db8::1'), so never compare addresses as strings, only as objects: str() always yields the canonical compressed form. The IPv4-mapped address '::ffff:1.2.3.4' is not equal to IPv4Address('1.2.3.4'); use .ipv4_mapped to extract the IPv4 part. Ordering against an IPv4Address raises TypeError.

Examples

import ipaddress
a = ipaddress.IPv6Address('2001:0db8:0000::0001')
print(a)  # → 2001:db8::1
print(a.exploded)  # → 2001:0db8:0000:0000:0000:0000:0000:0001
m = ipaddress.IPv6Address('::ffff:1.2.3.4')
print(m == ipaddress.IPv4Address('1.2.3.4'), m.ipv4_mapped)  # → False 1.2.3.4

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy