qwj / python-proxy

HTTP/HTTP2/HTTP3/Socks4/Socks5/Shadowsocks/ShadowsocksR/SSH/Redirect/Pf TCP/UDP asynchronous tunnel proxy implemented in Python 3 asyncio.
MIT License
2.01k stars 339 forks source link

how to do it in python #136

Open MdTalhaZubayer opened 3 years ago

MdTalhaZubayer commented 3 years ago

this is working on the cmd or terminal 'pproxy -r socks5://proxy:port#username:password. what will be the equivalent python code? please help.

Jonney commented 3 years ago

import pproxy args = '-r socks5://proxy:port#username:password' pproxy.server.main(args.split(' '))

lucydjo commented 2 years ago

import pproxy args = '-r socks5://proxy:port#username:password' pproxy.server.main(args.split(' '))

No matter what the arguments are, the server always starts the same way. And I can't connect to it. Can you help us?

args = '-r http://0.0.0.0:8000'

Output : Serving on :8080 by http,socks4,socks5

strangeh21 commented 2 years ago

Anyone struggling to get this working as a background process, I combined this with command_runner. https://pypi.org/project/command-runner/

Might be a pretty janky solution but it works for me:

from command_runner import command_runner_threaded

def main():
    global stop_running_proxy
    run_proxy(proxy_url, proxy_port, proxy_username, proxy_password, proxy_server_port)
    time.sleep(5)
    stop_proxy_answer = True

def run_proxy(proxy_host, proxy_port, proxy_user, proxy_pass, server_port):
    command_runner_threaded(
        f"pproxy -r http://{proxy_host}:{proxy_port}#{proxy_user}:{proxy_pass} -l http://:{server_port}", shell=True,
        stop_on=stop_proxy, check_interval=1)

def stop_proxy():
    while True:
        global stop_running_proxy
        is_true = stop_running_proxy
        time.sleep(1)
        if is_true:
            return True