ku-proxy


Nameku-proxy JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://gitlab.com/seeklay/ku
Summaryku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure Python 3
upload_time2023-07-08 13:24:04
maintainer
docs_urlNone
authorseeklay
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ku
ku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure [Python 3](https://www.python.org/).

![](https://img.shields.io/badge/Made%20with-Python-1f425f.svg) ![](https://img.shields.io/gitlab/license/seeklay/ku.svg) ![](https://tokei.rs/b1/gitlab/seeklay/ku) ![](https://badgen.net/pypi/v/ku-proxy) ![](https://img.shields.io/pypi/dw/ku-proxy?style=flat&logo=pypi) ![](https://gitlab.com/seeklay/ku/badges/main/pipeline.svg) ![](https://gitlab.com/seeklay/ku/badges/main/coverage.svg)

### Features
 - Dump data between clients and server
 - Spoof data in both directions
 - Drop data selectively
 - IPv6 Ready (pass upstream_6 for upstreaming ipv6 or enclose ipv6 addr in brackets like [::1] for listening addrs

### Is this proxy fast?
[Proxy speed comparison results](speedtest.md)

### TODO

 - [x] Tcp mitm proxy library
 - [x] Proxy executable script (kun (alpha))

### Installation
```bash
pip install -U ku-proxy
```
### Author
[seeklay](https://gitlab.com/seeklay/)

### License
[MIT](LICENSE)

### Simple proxy usage:
**Try to run this script and open http://localhost:80 in you browser**

```python
from ku import ku, tcpsession
from time import sleep

proxy = ku(("localhost", 80, "[::1]", 80), ("g.co", 80))

while 7:
    try:
        sleep(0.07)
    except KeyboardInterrupt:
        proxy.shutdown() #proxy creates a thread to async poll for socket events
        break            #we need to call shutdown() to break the thread loop
```

### Advanced proxy usage:

```python
from ku import ku, tcpsession, Pass, Reject
from time import sleep

class conn(tcpsession):

    def __init__(self, client, server, proxy):
        self.client = client
        self.server = server
        self.proxy = proxy
        self.id = id(self)        
        print(F"#{self.id} new conn {client.getpeername()}->{client.getsockname()}::{server.getsockname()}->{server.getpeername()}")

    def clientbound(self, data):        
        print(F"#{self.id} server->client  {len(data)}")
        print(data)
        return Pass

    def serverbound(self, data):        
        print(F"#{self.id} client->server  {len(data)}")
        print(data)
        #return None
        #in python None is returned by default, None == Pass

    def connection_made(self):
        print(F"#{self.id} connection_made")

    def connection_lost(self, side, err):
        side = 'client' if side is self.client else 'server' if side is not None else 'proxy'
        print(F"#{self.id} connection_lost by {side} due to {err}")

print("Starting...")
proxy = ku(("localhost", 80), ("api.ipify.org", 80), conn)
print("Started")

while 1:
    try:
        sleep(0.07)
    except KeyboardInterrupt:
        print("Shutting down...")
        proxy.shutdown()
        print("Exiting...")
        break
```

See [examples/](examples/) for more



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/seeklay/ku",
    "name": "ku-proxy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "seeklay",
    "author_email": "rudeboy@seeklay.icu",
    "download_url": "https://gitlab.com/seeklay/ku",
    "platform": "OS Independent",
    "description": "# ku\nku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure [Python 3](https://www.python.org/).\n\n![](https://img.shields.io/badge/Made%20with-Python-1f425f.svg) ![](https://img.shields.io/gitlab/license/seeklay/ku.svg) ![](https://tokei.rs/b1/gitlab/seeklay/ku) ![](https://badgen.net/pypi/v/ku-proxy) ![](https://img.shields.io/pypi/dw/ku-proxy?style=flat&logo=pypi) ![](https://gitlab.com/seeklay/ku/badges/main/pipeline.svg) ![](https://gitlab.com/seeklay/ku/badges/main/coverage.svg)\n\n### Features\n - Dump data between clients and server\n - Spoof data in both directions\n - Drop data selectively\n - IPv6 Ready (pass upstream_6 for upstreaming ipv6 or enclose ipv6 addr in brackets like [::1] for listening addrs\n\n### Is this proxy fast?\n[Proxy speed comparison results](speedtest.md)\n\n### TODO\n\n - [x] Tcp mitm proxy library\n - [x] Proxy executable script (kun (alpha))\n\n### Installation\n```bash\npip install -U ku-proxy\n```\n### Author\n[seeklay](https://gitlab.com/seeklay/)\n\n### License\n[MIT](LICENSE)\n\n### Simple proxy usage:\n**Try to run this script and open http://localhost:80 in you browser**\n\n```python\nfrom ku import ku, tcpsession\nfrom time import sleep\n\nproxy = ku((\"localhost\", 80, \"[::1]\", 80), (\"g.co\", 80))\n\nwhile 7:\n    try:\n        sleep(0.07)\n    except KeyboardInterrupt:\n        proxy.shutdown() #proxy creates a thread to async poll for socket events\n        break            #we need to call shutdown() to break the thread loop\n```\n\n### Advanced proxy usage:\n\n```python\nfrom ku import ku, tcpsession, Pass, Reject\nfrom time import sleep\n\nclass conn(tcpsession):\n\n    def __init__(self, client, server, proxy):\n        self.client = client\n        self.server = server\n        self.proxy = proxy\n        self.id = id(self)        \n        print(F\"#{self.id} new conn {client.getpeername()}->{client.getsockname()}::{server.getsockname()}->{server.getpeername()}\")\n\n    def clientbound(self, data):        \n        print(F\"#{self.id} server->client  {len(data)}\")\n        print(data)\n        return Pass\n\n    def serverbound(self, data):        \n        print(F\"#{self.id} client->server  {len(data)}\")\n        print(data)\n        #return None\n        #in python None is returned by default, None == Pass\n\n    def connection_made(self):\n        print(F\"#{self.id} connection_made\")\n\n    def connection_lost(self, side, err):\n        side = 'client' if side is self.client else 'server' if side is not None else 'proxy'\n        print(F\"#{self.id} connection_lost by {side} due to {err}\")\n\nprint(\"Starting...\")\nproxy = ku((\"localhost\", 80), (\"api.ipify.org\", 80), conn)\nprint(\"Started\")\n\nwhile 1:\n    try:\n        sleep(0.07)\n    except KeyboardInterrupt:\n        print(\"Shutting down...\")\n        proxy.shutdown()\n        print(\"Exiting...\")\n        break\n```\n\nSee [examples/](examples/) for more\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure Python 3",
    "version": "0.2.1",
    "project_urls": {
        "Download": "https://gitlab.com/seeklay/ku",
        "Homepage": "https://gitlab.com/seeklay/ku"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8cd5c74f308ac5e18b33c23a42e55ba316b7b98406681259d2f7a501ab99ad84",
                "md5": "e0521ddb70ccf7273a7e89aa6a6e1283",
                "sha256": "9408683a53e4767b5aa0d4f8e11778f53135c2b9474128db2b4bbd6cd9876079"
            },
            "downloads": -1,
            "filename": "ku_proxy-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0521ddb70ccf7273a7e89aa6a6e1283",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10563,
            "upload_time": "2023-07-08T13:24:04",
            "upload_time_iso_8601": "2023-07-08T13:24:04.971981Z",
            "url": "https://files.pythonhosted.org/packages/8c/d5/c74f308ac5e18b33c23a42e55ba316b7b98406681259d2f7a501ab99ad84/ku_proxy-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-08 13:24:04",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "seeklay",
    "gitlab_project": "ku",
    "lcname": "ku-proxy"
}
        
Elapsed time: 0.07932s