Skip to main content

PySocks5Server

Simple socks5 proxy server written in python.

Installation

Requirements:

  • Python 3.10+
pip install pysocks5server

Usage

Usage: python -m socks5server [-h] [--host HOST] [--port PORT] [--no-auth] [--users [USERS ...]]

options:
  -h, --help           show this help message and exit
  --host HOST
  --port PORT
  --no-auth            Allow connections without authentication.
  --users [USERS ...]  List of users. Example: "--users user1:password1 user2:password2"

TODO

  • TCP/IP port binding
  • UDP port association
  • Socks4/socks4a support?

Code examples

Run server without authentication

from asyncio import get_event_loop
from socks5server import SocksServer

server = SocksServer("0.0.0.0", 1080, True)

if __name__ == '__main__':
    get_event_loop().run_until_complete(server.serve())

Run server with callbacks

from asyncio import get_event_loop
from socks5server import SocksServer, Socks5Client, DataDirection

server = SocksServer("0.0.0.0", 1080, True)

@server.on_client_connected
async def client_connected(client: Socks5Client):
    print(f"Client connected: {client}")
    
    
@server.on_client_disconnected
async def client_disconnected(client: Socks5Client):
    print(f"Client disconnected: {client}")
    
    
@server.on_data
async def data_received(client: Socks5Client, direction: DataDirection, data: bytes):
    print(f"{direction} | {data}")

    
if __name__ == '__main__':
    get_event_loop().run_until_complete(server.serve())

Run server with password authentication

from asyncio import get_event_loop
from socks5server import SocksServer, PasswordAuthentication

server = SocksServer("0.0.0.0", 1080)
users = {"test_login1": "test_password1", "login": "password"}
server.register_authentication(0x02, PasswordAuthentication(users))  # 0x02 is password authentication type

if __name__ == '__main__':
    get_event_loop().run_until_complete(server.serve())

Run server with custom authentication

All Authentication methods

import asyncio
from asyncio import get_event_loop
from socks5server import SocksServer, AuthenticationBase


class ChallengeHandshakeAuthentication(AuthenticationBase):
    async def authenticate(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> bool:
        ... # Implement authentication process
    
        return True


server = SocksServer("0.0.0.0", 1080)

# 0x03 is type of Challenge–Handshake Authentication Protocol
server.register_authentication(0x03, ChallengeHandshakeAuthentication())

if __name__ == '__main__':
    get_event_loop().run_until_complete(server.serve())

Metadata

Release files for pysocks5server 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysocks5server 0.1.2
File Size Uploaded
pysocks5server-0.1.2.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysocks5server 0.1.2
File Interpreter ABI Platform
pysocks5server-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / pysocks5server-0.1.2.tar.gz

Download URL pysocks5server-0.1.2.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e368d06d8cc69282c2654a31e2e14cb7a4990f0b9b2503a6c906024fca9f55b0
BLAKE2b-256 checksum
How to use checksums
2f8bb40819897a8191b416acd695ad41999fe788d4bcddb1d3fc24c6aef667bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.13.7 Linux/6.14.9-200.fc41.x86_64

Release files / pysocks5server-0.1.2-py3-none-any.whl

Download URL pysocks5server-0.1.2-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fa357c2b0ca93a37254520ea2f322db438a44186d87c2d25df37a70ae67d62e
BLAKE2b-256 checksum
How to use checksums
949f93bcc329fb00f645bbe6085d0d2c39cc0fb3fe99db6e6f04ca5b7d809e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.13.7 Linux/6.14.9-200.fc41.x86_64

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page