socks-client
The socks-client package provides a core proxy client functionality for Python. Supports SOCKS4 proxy and SOCKS5 proxy and provides sync and async APIs. You probably don't need to use socks-client directly.
Features
- Supports both TCP and UDP client with the implementation of SOCKS5 and SOCKS4 protocol
- Supports username/password authentication and no authentication
- Driven by the python standard library, no third-party dependencies
Installation
Install with pip if Python version 3.7.0 or higher is available.
$ pip install socks-client
pypi:https://pypi.org/project/socks-client/
Usage
Async TCP Client
import socks_client.tcp_async as socks
async def tcp_client_through_socks(proxy_host, proxy_port, target_host, target_port):
tcp_socks = socks.socksocket(
proxy_type=socks.SOCKS5,
proxy_host=proxy_host,
proxy_port=proxy_port,
username="my_username",
password="my_password",
rdns=False,
)
await tcp_socks.settimeout(5)
sock = await tcp_socks.connect(dest_host=target_host, dest_port=target_port)
reader, writer = await asyncio.open_connection(
host=None,
port=None,
sock=sock,
)
request = (
b"GET / HTTP/1.1\r\n" b"Host: ip.sb\r\n" b"User-Agent: curl/7.64.0\r\n\r\n"
)
writer.write(request)
response = await asyncio.wait_for(reader.read(1024), timeout=1)
Sync TCP Client
import socks_client.tcp_sync as socks
def tcp_client_through_socks(proxy_host, proxy_port, target_host, target_port):
tcp_socks = socks.socksocket()
tcp_socks.setproxy(
socks.SOCKS5,
proxy_host,
proxy_port,
rdns=False,
username="my_username",
password="my_password",
)
tcp_socks.settimeout(5)
tcp_socks.connect_ex((target_host, target_port))
request = (
b"GET / HTTP/1.1\r\n" b"Host: ip.sb\r\n" b"User-Agent: curl/7.64.0\r\n\r\n"
)
tcp_socks.send(request)
response_headers = tcp_socks.recv(4096).decode()
Async UDP Client
import socks_client.udp_async as socks
async def udp_client_through_socks(
proxy_host, proxy_port, target_host, target_port, message
):
await socks.setdefaultproxy(
socks.SOCKS5,
proxy_host,
proxy_port,
rdns=True,
username="my_username",
password="my_password",
)
socket.socket = socks.socksocket
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
await udp_socket.settimeout(5)
await udp_socket.sendto(message.encode(), (target_host, target_port))
response, server_address = await udp_socket.recvfrom(1024)
Sync UDP Client
import socks_client.udp_sync as socks
def udp_client_through_socks(proxy_host, proxy_port, target_host, target_port, message):
socks.setdefaultproxy(
socks.SOCKS5,
proxy_host,
proxy_port,
rdns=False,
username="my_username",
password="my_password",
)
socket.socket = socks.socksocket
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.settimeout(5)
udp_socket.sendto(message.encode(), (target_host, target_port))
response, server_address = udp_socket.recvfrom(1024)
print("Response from server:", response.decode())
Reference
Metadata
Release files for socks-client 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| socks-client-2.0.1.tar.gz | 16.2 kB | Without provenance | Details for socks-client-2.0.1.tar.gz |
Release files / socks-client-2.0.1.tar.gz
| Download URL | socks-client-2.0.1.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b114d8d67377b12edb68e4390a791667cc5384944a31f6da3a1c5fa7754fbf1
|
|
BLAKE2b-256 checksum How to use checksums |
2806f14442b293b1bafa04dc41ce8686b6359b3b42a6da335605962e2367dbe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.2
|
Security for socks-client 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.