Metadata-Version: 2.1
Name: ku-proxy
Version: 0.1.0
Summary: ku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure Python 3
Home-page: https://gitlab.com/seeklay/ku
Author: seeklay
Author-email: rudeboy@seeklay.icu
License: MIT
Download-URL: https://gitlab.com/seeklay/ku
Platform: OS Independent
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown

# ku

### About
ku is fast, async, modern, little tcp man-in-the-middle proxy library

### Author
[seeklay](https://gitlab.com/seeklay/)

### License
[MIT](LICENSE)

### TODO

 - [x] Tcp mitm proxy library
 - [ ] Proxy executable script

### Features
 - Dump data between clients and server
 - Spoof data in both directions
 - Drop data selectively

### Installation
```bash
pip install -U ku-proxy
```

### 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), ("api.ipify.com", 80))
# now the proxy is already running

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)

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

    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


