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) → Union[socksio.socks5.SOCKS5AuthReply, socksio.socks5.SOCKS5Reply, socksio.socks5.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: Union[socksio.socks5.SOCKS5AuthMethodsRequest, socksio.socks5.SOCKS5CommandRequest]) → 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.
-
state
¶ Returns the current state of the protocol.
-
-
class
socksio.socks5.
SOCKS5AuthMethodsRequest
¶ 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
¶ 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) → socksio.socks5.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.
-
classmethod
-
class
socksio.socks5.
SOCKS5UsernamePasswordRequest
¶ 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
¶ Encapsulates a username/password authentication reply from the proxy server.
-
classmethod
loads
(data: bytes) → socksio.socks5.SOCKS5UsernamePasswordReply¶ Unpacks the reply authentication data into an instance.
Returns: The unpacked authentication reply instance.
-
classmethod
-
class
socksio.socks5.
SOCKS5CommandRequest
¶ 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: socksio.socks5.SOCKS5Command, address: Union[str, bytes, Tuple[Union[str, bytes], int]]) → socksio.socks5.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
¶ 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) → socksio.socks5.SOCKS5Reply¶ Unpacks the reply data into an instance.
Returns: The unpacked reply instance. Raises: ProtocolError
– If the data does not match the spec.