Skip to content

ws-tunnel

ws-tunnel, an open-source project by Yaroslav Koval.

ws-tunnel is an open-source project by Yaroslav Koval, written mainly in TypeScript. Last updated: Jun 13, 2026. The source code is on GitHub.

  • TypeScript
  • cloudflare
  • cloudflare-workers
  • p2p
  • workers
Updated
Stars
0
git clone https://github.com/koval01/ws-tunnel.git

README

"""example"""
import asyncio
import websockets
import requests
import json
import time
import sys

BASE_URL = "ws-tunnel.koval.workers.dev"

API_URL = f"https://{BASE_URL}"
WS_URL = f"wss://{BASE_URL}"

async def listen_for_messages(ws):
    try:
        async for message in ws:
            try:
                data = json.loads(message)
                msg_type = data.get("type")
                payload = data.get("payload", "")

                # Worker system messages
                if msg_type == "system":
                    print(f"\r[SYSTEM]: {payload}\n> ", end="", flush=True)

                # Standard chat messages
                elif msg_type == "chat":
                    print(f"\r[PEER]: {payload}\n> ", end="", flush=True)

                # Remote command execution requests
                elif msg_type == "command":
                    print(f"\r[SYSTEM]: Executing remote command: {payload}\n> ", end="", flush=True)

                    try:
                        output = "cmd" # Replace with actual subprocess execution
                        if not output:
                            output = "[Success: No output]"
                    except Exception as e:
                        output = f"[Error executing command]: {str(e)}"

                    # Pack execution result into data payload
                    response = json.dumps({
                        "type": "data",
                        "payload": f"exec_res:{output}"
                    })
                    await ws.send(response)

                # Processing multiplexed data (pings, command outputs)
                elif msg_type == "data":
                    if payload.startswith("ping_req:"):
                        ts = payload.split(":", 1)[1]
                        pong = json.dumps({"type": "data", "payload": f"ping_res:{ts}"})
                        await ws.send(pong)

                    elif payload.startswith("ping_res:"):
                        ts_str = payload.split(":", 1)[1]
                        rtt_ms = (time.time() - float(ts_str)) * 1000
                        print(f"\r[PING]: {rtt_ms:.2f} ms\n> ", end="", flush=True)

                    elif payload.startswith("exec_res:"):
                        output = payload.split(":", 1)[1]
                        print(f"\r\n--- [ REMOTE OUTPUT ] ---\n{output}\n-------------------------\n> ", end="", flush=True)

            except json.JSONDecodeError:

[... continued on GitHub]

More projects

All repositories: github.com/koval01