SOCKS5 API documentation

class socksio.socks5.SOCKS5Connection

Encapsulates a SOCKS5 connection.

Packs request objects into data suitable to be send and unpacks reply data into their appropriate reply objects.

data_to_send() bytes

Returns the data to be sent via the I/O library of choice.

Also clears the connection’s buffer.

receive_data(data: bytes) SOCKS5AuthReply | SOCKS5Reply | SOCKS5UsernamePasswordReply

Unpacks response data into a reply object.

Parameters:

data – The raw response data from the proxy server.

Returns:

A reply instance corresponding to the connection state and reply data.

send(request: SOCKS5AuthMethodsRequest | SOCKS5CommandRequest) None
send(request: SOCKS5AuthMethodsRequest) None
send(request: SOCKS5UsernamePasswordRequest) None
send(request: SOCKS5AuthMethodsRequest) None

Packs a request object and adds it to the send data buffer.

Also progresses the protocol state of the connection.

Parameters:

request – The request instance to be packed.

property state: SOCKS5State

Returns the current state of the protocol.

class socksio.socks5.SOCKS5AuthMethodsRequest(methods: List[SOCKS5AuthMethod])

Encapsulates a request to the proxy for available authentication methods.

Parameters:

methods – A list of acceptable authentication methods.

dumps() bytes

Packs the instance into a raw binary in the appropriate form.

class socksio.socks5.SOCKS5AuthReply(method: SOCKS5AuthMethod)

Encapsulates a reply from the proxy with the authentication method to be used.

Parameters:

method – The authentication method to be used.

Raises:

ProtocolError – If the data does not conform with the expected structure.

classmethod loads(data: bytes) SOCKS5AuthReply

Unpacks the authentication reply data into an instance.

Returns:

The unpacked authentication reply instance.

Raises:

ProtocolError – If the data does not match the spec.

class socksio.socks5.SOCKS5UsernamePasswordRequest(username: bytes, password: bytes)

Encapsulates a username/password authentication request to the proxy server.

dumps() bytes

Packs the instance into a raw binary in the appropriate form.

Returns:

The packed request.

class socksio.socks5.SOCKS5UsernamePasswordReply(success: bool)

Encapsulates a username/password authentication reply from the proxy server.

classmethod loads(data: bytes) SOCKS5UsernamePasswordReply

Unpacks the reply authentication data into an instance.

Returns:

The unpacked authentication reply instance.

class socksio.socks5.SOCKS5CommandRequest(command: SOCKS5Command, atype: SOCKS5AType, addr: bytes, port: int)

Encapsulates a command request to the proxy server.

Parameters:
  • command – The command to request.

  • atype – The address type of the addr field.

  • addr – Address of the target host.

  • port – The port number to connect to on the target host.

dumps() bytes

Packs the instance into a raw binary in the appropriate form.

Returns:

The packed request.

classmethod from_address(command: SOCKS5Command, address: str | bytes | Tuple[str | bytes, int]) SOCKS5CommandRequest

Convenience class method to build an instance from command and address.

Parameters:
  • command – The command to request.

  • address – A string in the form ‘HOST:PORT’ or a tuple of ip address string and port number. The address type will be inferred.

Returns:

A SOCKS5CommandRequest instance.

Raises:

SOCKSError – If a domain name or IPv6 address was supplied.

class socksio.socks5.SOCKS5Reply(reply_code: SOCKS5ReplyCode, atype: SOCKS5AType, addr: str, port: int)

Encapsulates a reply from the SOCKS5 proxy server

Parameters:
  • reply_code – The code representing the type of reply.

  • atype – The address type of the addr field.

  • addr – Optional IP address returned.

  • port – The port number returned.

classmethod loads(data: bytes) SOCKS5Reply

Unpacks the reply data into an instance.

Returns:

The unpacked reply instance.

Raises:

ProtocolError – If the data does not match the spec.