socks-client


Namesocks-client JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/plattanus/socks-client
SummarySupports both TCP and UDP client with the implementation of SOCKS5 and SOCKS4 protocol
upload_time2023-12-31 11:57:01
maintainer
docs_urlNone
authorPlattanus
requires_python>=3.7
licenseMIT License
keywords socks socks5 socks4 proxy asyncio tcp udp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.**

```shell
$ pip install socks-client
```

pypi:https://pypi.org/project/socks-client/

## Usage

**Async TCP Client**

```python
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**

```python
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**

```python
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**

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

* [Amaindex/socks server](https://github.com/Amaindex/asyncio-socks-server.git)
* [Anorov/PySocks](https://github.com/Anorov/PySocks.git)
* [romis2012/python-socks](https://github.com/romis2012/python-socks.git)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/plattanus/socks-client",
    "name": "socks-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "socks,socks5,socks4,proxy,asyncio,tcp,udp",
    "author": "Plattanus",
    "author_email": "plattanus@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/28/06/f14442b293b1bafa04dc41ce8686b6359b3b42a6da335605962e2367dbe7/socks-client-2.0.1.tar.gz",
    "platform": null,
    "description": "# socks-client\n\nThe `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.\n\n## Features\n\n* **Supports both TCP and UDP client with the implementation of SOCKS5 and SOCKS4 protocol**\n* **Supports username/password authentication and no authentication**\n* **Driven by the python standard library, no third-party dependencies**\n\n## Installation\n\n**Install with pip if Python version 3.7.0 or higher is available.**\n\n```shell\n$ pip install socks-client\n```\n\npypi\uff1ahttps://pypi.org/project/socks-client/\n\n## Usage\n\n**Async TCP Client**\n\n```python\nimport socks_client.tcp_async as socks\nasync def tcp_client_through_socks(proxy_host, proxy_port, target_host, target_port):\n    tcp_socks = socks.socksocket(\n        proxy_type=socks.SOCKS5,\n        proxy_host=proxy_host,\n        proxy_port=proxy_port,\n        username=\"my_username\",\n        password=\"my_password\",\n        rdns=False,\n    )\n    await tcp_socks.settimeout(5)\n    sock = await tcp_socks.connect(dest_host=target_host, dest_port=target_port)\n\n    reader, writer = await asyncio.open_connection(\n        host=None,\n        port=None,\n        sock=sock,\n    )\n    request = (\n        b\"GET / HTTP/1.1\\r\\n\" b\"Host: ip.sb\\r\\n\" b\"User-Agent: curl/7.64.0\\r\\n\\r\\n\"\n    )\n    writer.write(request)\n    response = await asyncio.wait_for(reader.read(1024), timeout=1)\n```\n\n**Sync TCP Client**\n\n```python\nimport socks_client.tcp_sync as socks\ndef tcp_client_through_socks(proxy_host, proxy_port, target_host, target_port):\n    tcp_socks = socks.socksocket()\n    tcp_socks.setproxy(\n        socks.SOCKS5,\n        proxy_host,\n        proxy_port,\n        rdns=False,\n        username=\"my_username\",\n        password=\"my_password\",\n    )\n    tcp_socks.settimeout(5)\n    tcp_socks.connect_ex((target_host, target_port))\n    request = (\n        b\"GET / HTTP/1.1\\r\\n\" b\"Host: ip.sb\\r\\n\" b\"User-Agent: curl/7.64.0\\r\\n\\r\\n\"\n    )\n    tcp_socks.send(request)\n    response_headers = tcp_socks.recv(4096).decode()\n```\n\n**Async UDP Client**\n\n```python\nimport socks_client.udp_async as socks\nasync def udp_client_through_socks(\n    proxy_host, proxy_port, target_host, target_port, message\n):\n    await socks.setdefaultproxy(\n        socks.SOCKS5,\n        proxy_host,\n        proxy_port,\n        rdns=True,\n        username=\"my_username\",\n        password=\"my_password\",\n    )\n    socket.socket = socks.socksocket\n    udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n    await udp_socket.settimeout(5)\n    await udp_socket.sendto(message.encode(), (target_host, target_port))\n    response, server_address = await udp_socket.recvfrom(1024)\n```\n\n**Sync UDP Client**\n\n```python\nimport socks_client.udp_sync as socks\ndef udp_client_through_socks(proxy_host, proxy_port, target_host, target_port, message):\n    socks.setdefaultproxy(\n        socks.SOCKS5,\n        proxy_host,\n        proxy_port,\n        rdns=False,\n        username=\"my_username\",\n        password=\"my_password\",\n    )\n    socket.socket = socks.socksocket\n    udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n    udp_socket.settimeout(5)\n    udp_socket.sendto(message.encode(), (target_host, target_port))\n    response, server_address = udp_socket.recvfrom(1024)\n    print(\"Response from server:\", response.decode())\n```\n\n## Reference\n\n* [Amaindex/socks server](https://github.com/Amaindex/asyncio-socks-server.git)\n* [Anorov/PySocks](https://github.com/Anorov/PySocks.git)\n* [romis2012/python-socks](https://github.com/romis2012/python-socks.git)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Supports both TCP and UDP client with the implementation of SOCKS5 and SOCKS4 protocol",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/plattanus/socks-client"
    },
    "split_keywords": [
        "socks",
        "socks5",
        "socks4",
        "proxy",
        "asyncio",
        "tcp",
        "udp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2806f14442b293b1bafa04dc41ce8686b6359b3b42a6da335605962e2367dbe7",
                "md5": "cf751f12fdc36259bd285eabfc9f7c1d",
                "sha256": "8b114d8d67377b12edb68e4390a791667cc5384944a31f6da3a1c5fa7754fbf1"
            },
            "downloads": -1,
            "filename": "socks-client-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cf751f12fdc36259bd285eabfc9f7c1d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 16179,
            "upload_time": "2023-12-31T11:57:01",
            "upload_time_iso_8601": "2023-12-31T11:57:01.755461Z",
            "url": "https://files.pythonhosted.org/packages/28/06/f14442b293b1bafa04dc41ce8686b6359b3b42a6da335605962e2367dbe7/socks-client-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-31 11:57:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "plattanus",
    "github_project": "socks-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "socks-client"
}
        
Elapsed time: 0.16158s