pysocks5server


Namepysocks5server JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummarySimple socks5 proxy server
upload_time2024-02-06 18:24:32
maintainer
docs_urlNone
authorRuslanUC
requires_python>=3.10,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PySocks5Server

Simple socks5 proxy server written in python (I was bored).

## Installation
**Requirements:**
  - Python 3.10+

```shell
pip install socksserver
```

## Usage
```shell
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
```python
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
```python
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
```python
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](https://en.wikipedia.org/wiki/SOCKS#:~:text=methods%20supported%2C%20uint8-,AUTH,-Authentication%20methods%2C%201)

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pysocks5server",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "RuslanUC",
    "author_email": "dev_ruslan_uc@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/ed/ea6ad3d193eb937ad1ab58ba0c64cdaf93949d64a9e33dafd706def04394/pysocks5server-0.1.0.tar.gz",
    "platform": null,
    "description": "# PySocks5Server\n\nSimple socks5 proxy server written in python (I was bored).\n\n## Installation\n**Requirements:**\n  - Python 3.10+\n\n```shell\npip install socksserver\n```\n\n## Usage\n```shell\nUsage: python -m socks5server [-h] [--host HOST] [--port PORT] [--no-auth] [--users [USERS ...]]\n\noptions:\n  -h, --help           show this help message and exit\n  --host HOST\n  --port PORT\n  --no-auth            Allow connections without authentication.\n  --users [USERS ...]  List of users. Example: \"--users user1:password1 user2:password2\"\n```\n\n## TODO\n  - [ ] TCP/IP port binding\n  - [ ] UDP port association\n  - [ ] Socks4/socks4a support?\n\n## Code examples\n\n### Run server without authentication\n```python\nfrom asyncio import get_event_loop\nfrom socks5server import SocksServer\n\nserver = SocksServer(\"0.0.0.0\", 1080, True)\n\nif __name__ == '__main__':\n    get_event_loop().run_until_complete(server.serve())\n```\n\n### Run server with callbacks\n```python\nfrom asyncio import get_event_loop\nfrom socks5server import SocksServer, Socks5Client, DataDirection\n\nserver = SocksServer(\"0.0.0.0\", 1080, True)\n\n@server.on_client_connected\nasync def client_connected(client: Socks5Client):\n    print(f\"Client connected: {client}\")\n    \n    \n@server.on_client_disconnected\nasync def client_disconnected(client: Socks5Client):\n    print(f\"Client disconnected: {client}\")\n    \n    \n@server.on_data\nasync def data_received(client: Socks5Client, direction: DataDirection, data: bytes):\n    print(f\"{direction} | {data}\")\n\n    \nif __name__ == '__main__':\n    get_event_loop().run_until_complete(server.serve())\n```\n\n### Run server with password authentication\n```python\nfrom asyncio import get_event_loop\nfrom socks5server import SocksServer, PasswordAuthentication\n\nserver = SocksServer(\"0.0.0.0\", 1080)\nusers = {\"test_login1\": \"test_password1\", \"login\": \"password\"}\nserver.register_authentication(0x02, PasswordAuthentication(users))  # 0x02 is password authentication type\n\nif __name__ == '__main__':\n    get_event_loop().run_until_complete(server.serve())\n```\n\n### Run server with custom authentication\n[All Authentication methods](https://en.wikipedia.org/wiki/SOCKS#:~:text=methods%20supported%2C%20uint8-,AUTH,-Authentication%20methods%2C%201)\n\n```python\nimport asyncio\nfrom asyncio import get_event_loop\nfrom socks5server import SocksServer, AuthenticationBase\n\n\nclass ChallengeHandshakeAuthentication(AuthenticationBase):\n    async def authenticate(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> bool:\n        ... # Implement authentication process\n    \n        return True\n\n\nserver = SocksServer(\"0.0.0.0\", 1080)\n\n# 0x03 is type of Challenge\u2013Handshake Authentication Protocol\nserver.register_authentication(0x03, ChallengeHandshakeAuthentication())\n\nif __name__ == '__main__':\n    get_event_loop().run_until_complete(server.serve())\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple socks5 proxy server",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "707ff14d2725d6a8e635ba64834ce1701dc89e4a34fcc3544e9acfd5b24a3533",
                "md5": "61b68ebd0baf0d5be8bd453ee1325d85",
                "sha256": "fbcdb7ca854fcc6b213b3e095a56dba38acfc779c6f5954cf526d1105d73dea2"
            },
            "downloads": -1,
            "filename": "pysocks5server-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61b68ebd0baf0d5be8bd453ee1325d85",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 7528,
            "upload_time": "2024-02-06T18:24:30",
            "upload_time_iso_8601": "2024-02-06T18:24:30.140224Z",
            "url": "https://files.pythonhosted.org/packages/70/7f/f14d2725d6a8e635ba64834ce1701dc89e4a34fcc3544e9acfd5b24a3533/pysocks5server-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9edea6ad3d193eb937ad1ab58ba0c64cdaf93949d64a9e33dafd706def04394",
                "md5": "70240ba23fabb4ae985a4ca53e6d699e",
                "sha256": "9a018b80aa98fefebc9812bbf20ad8dbdcdf593c2dbe3a9bbbe70034de7c9145"
            },
            "downloads": -1,
            "filename": "pysocks5server-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "70240ba23fabb4ae985a4ca53e6d699e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 5346,
            "upload_time": "2024-02-06T18:24:32",
            "upload_time_iso_8601": "2024-02-06T18:24:32.159734Z",
            "url": "https://files.pythonhosted.org/packages/e9/ed/ea6ad3d193eb937ad1ab58ba0c64cdaf93949d64a9e33dafd706def04394/pysocks5server-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-06 18:24:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pysocks5server"
}
        
Elapsed time: 0.40755s