Skip to main content

Simple socks5 proxy server

Project description

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysocks5server-0.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysocks5server-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pysocks5server-0.1.1.tar.gz.

File metadata

  • Download URL: pysocks5server-0.1.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.7 Linux/6.14.9-200.fc41.x86_64

File hashes

Hashes for pysocks5server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 31bc901bc15776a47052e5d58180c1cd5831bb8738b54279c8a204aad0fe72c0
MD5 4d3210dfabeee106b2af98ae65d68be2
BLAKE2b-256 2937f13881f6056f592bd750b96f1d0dad37da8707c04d03b5e02d7b80ab4694

See more details on using hashes here.

File details

Details for the file pysocks5server-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pysocks5server-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.7 Linux/6.14.9-200.fc41.x86_64

File hashes

Hashes for pysocks5server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa565b121b49ba2fff472eddc93360ce00b272ffc840fcde752b5422ecda43b7
MD5 a69fc83700df70dea68f8c34beeece0c
BLAKE2b-256 099d4f4337aa54e57000e14212ea7dbe32593884cf51cf0e8b6463c327e464d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page