mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 14:00:01 -04:00
add proxy server code
This commit is contained in:
parent
dfd9a7a8ae
commit
953b6cb191
6 changed files with 75 additions and 10 deletions
43
server/main.py
Normal file
43
server/main.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import logging
|
||||
import threading
|
||||
import os
|
||||
|
||||
from asyncio_socks_server.app import SocksServer
|
||||
from websockify.websocketproxy import WebSocketProxy
|
||||
|
||||
#start a socks5 proxy as well as websockify
|
||||
|
||||
def setup_logging(prefix):
|
||||
stderr_handler = logging.StreamHandler()
|
||||
stderr_handler.setLevel(logging.DEBUG)
|
||||
log_formatter = logging.Formatter(prefix + "%(message)s")
|
||||
stderr_handler.setFormatter(log_formatter)
|
||||
root = logging.getLogger()
|
||||
root.addHandler(stderr_handler)
|
||||
root.setLevel(logging.INFO)
|
||||
|
||||
def start_websockify():
|
||||
options = {
|
||||
"listen_host": "127.0.0.1",
|
||||
"listen_port": 6001,
|
||||
"target_host": "127.0.0.1",
|
||||
"target_port": 1080
|
||||
}
|
||||
|
||||
server = WebSocketProxy(**options)
|
||||
server.start_server()
|
||||
|
||||
def start_socks():
|
||||
socks_app = SocksServer(
|
||||
LISTEN_HOST="127.0.0.1",
|
||||
LISTEN_PORT=1080
|
||||
)
|
||||
socks_app.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
pid = os.fork()
|
||||
if pid == 0:
|
||||
setup_logging("[websockify] ")
|
||||
start_websockify()
|
||||
else:
|
||||
start_socks()
|
2
server/requirements.txt
Normal file
2
server/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
websockify
|
||||
asyncio-socks-server
|
16
server/run.sh
Executable file
16
server/run.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
#install dependencies and run the proxy server
|
||||
|
||||
set -e
|
||||
|
||||
if [ ! -d ".venv" ]; then
|
||||
python3 -m venv .venv
|
||||
fi
|
||||
source .venv/bin/activate
|
||||
|
||||
if ! python3 -c "import asyncio_socks_server, websockify" 2> /dev/null; then
|
||||
pip3 install -r requirements.txt
|
||||
fi
|
||||
|
||||
python3 main.py
|
Loading…
Add table
Add a link
Reference in a new issue