proxyprotocol.sock

class proxyprotocol.sock.SocketInfo(transport)[source]

Provides information about the connection, from either the underlying asyncio transport layer or overridden by the PROXY protocol result.

Parameters:

transport (TransportProtocol)

classmethod get(transport, result, *, unique_id=b'', dnsbl=None)[source]

Choose the SocketInfo implementation based on whether the result indicates the connection is proxied.

Parameters:
  • transport (TransportProtocol) – The BaseTransport or StreamWriter for the connection.

  • result (ProxyResult | None) – The PROXY protocol result.

  • unique_id (bytes) – A unique ID to associate with the connection, unless overridden by the PROXY protocol result.

  • dnsbl (str | None) – The DNSBL lookup result, if any.

Return type:

SocketInfo

property socket: socket

The underlying socket object.

abstract property sockname: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The local address of the socket.

property sockname_ip: None | IPv4Address | IPv6Address

The IP address object from sockname, for AF_INET or AF_INET6 connections.

property sockname_port: int | None

The port number from sockname, for AF_INET or AF_INET6 connections.

property sockname_str: str | None

The sockname address as a string. For AF_INET/AF_INET6 families, this is ip:port.

abstract property peername: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The remote address of the socket.

property peername_ip: None | IPv4Address | IPv6Address

The IP address object from peername, for AF_INET or AF_INET6 connections.

property peername_port: int | None

The port number from peername, for AF_INET or AF_INET6 connections.

property peername_str: str | None

The peername address as a string. For AF_INET/AF_INET6 families, this is ip:port.

abstract property family: AddressFamily

The socket address family.

abstract property protocol: SocketKind | None

The socket protocol.

abstract property compression: str | None

The compression() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

abstract property cipher: Tuple[str, str, int | None] | None

The cipher() value for encrypted connections.

Note

For proxied connections, this data may be unavailable or partially available, depending on the server implementation and PROXY protocol version.

abstract property peercert: Mapping[str, Any] | None

The getpeercert() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

abstract property unique_id: bytes

A unique identifier for the connection. For proxied connections, the unique ID from the header (if any) is returned, otherwise returns the value passed in to the constructor.

abstract property dnsbl: str | None

The DNSBL lookup result of the connecting IP address, if any.

This value is contextual to the DNSBL in use, but generally any value here other than None indicates the IP address should be blocked.

property from_localhost: bool

True for local socket connections, if:

To be specific, True for AF_UNIX connections and True for IPv4/IPv6 connections with True is_loopback flags.

class proxyprotocol.sock.SocketInfoProxy(transport, result)[source]

Provides information about the connection, overridden by the PROXY protocol result.

Parameters:
property sockname: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The local address of the socket.

property peername: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The remote address of the socket.

property family: AddressFamily

The socket address family.

property protocol: SocketKind | None

The socket protocol.

property compression: str | None

The compression() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

property cipher: Tuple[str, str, int | None] | None

The cipher() value for encrypted connections.

Note

For proxied connections, this data may be unavailable or partially available, depending on the server implementation and PROXY protocol version.

property peercert: Mapping[str, Any] | None

The getpeercert() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

property unique_id: bytes

A unique identifier for the connection. For proxied connections, the unique ID from the header (if any) is returned, otherwise returns the value passed in to the constructor.

property dnsbl: str | None

The DNSBL lookup result of the connecting IP address, if any.

This value is contextual to the DNSBL in use, but generally any value here other than None indicates the IP address should be blocked.

class proxyprotocol.sock.SocketInfoLocal(transport, *, unique_id=b'', dnsbl=None)[source]

Provides information about the connection, from the underlying asyncio transport layer.

Parameters:
  • transport (TransportProtocol) – The BaseTransport or StreamWriter for the connection.

  • unique_id (bytes) – A unique ID to associate with the connection, unless overridden by the PROXY protocol result.

  • dnsbl (Optional[str]) – The DNSBL lookup result, if any.

property sockname: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The local address of the socket.

property peername: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The remote address of the socket.

property family: AddressFamily

The socket address family.

property protocol: SocketKind | None

The socket protocol.

property compression: str | None

The compression() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

property cipher: Tuple[str, str, int | None] | None

The cipher() value for encrypted connections.

Note

For proxied connections, this data may be unavailable or partially available, depending on the server implementation and PROXY protocol version.

property peercert: Mapping[str, Any] | None

The getpeercert() value for encrypted connections.

Note

For proxied connections, this data may be unavailable, depending on the server implementation and PROXY protocol version.

property unique_id: bytes

A unique identifier for the connection. For proxied connections, the unique ID from the header (if any) is returned, otherwise returns the value passed in to the constructor.

property dnsbl: str | None

The DNSBL lookup result of the connecting IP address, if any.

This value is contextual to the DNSBL in use, but generally any value here other than None indicates the IP address should be blocked.