Python Glossary Русский

Python 3.8+socketfunction

socket.has_dualstack_ipv6()

creating sockets

Checks whether the system supports a single IPv6 socket that accepts both IPv4 and IPv6 connections.

Syntax

socket.has_dualstack_ipv6() -> bool

The answer depends on the OS and its settings, not on Python: in containers and on hosts with IPv6 disabled it is False, so passing dualstack_ipv6=True without this check raises ValueError. With a dual stack an IPv4 client appears in getpeername() as '::ffff:127.0.0.1' rather than '127.0.0.1', which breaks code that compares addresses as strings.

Examples

import socket
print(socket.has_dualstack_ipv6())  # → ? True или False — зависит от системы
if socket.has_dualstack_ipv6():
    srv = socket.create_server(('', 0), family=socket.AF_INET6, dualstack_ipv6=True)
else:
    srv = socket.create_server(('', 0))
print(srv.family.name)  # → ? AF_INET6 или AF_INET
srv.close()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy