From 8a2e1006b3b272126332aa064f3ad95387129544 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 13 Feb 2025 14:13:49 +0530 Subject: new dot files --- .../zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 .config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py (limited to '.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py') diff --git a/.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py b/.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py new file mode 100755 index 0000000..a498c84 --- /dev/null +++ b/.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +import os +import subprocess +import sys +from urllib.parse import urlparse + +proxy = next(os.environ[_] for _ in ("HTTP_PROXY", "HTTPS_PROXY") if _ in os.environ) + +parsed = urlparse(proxy) + +proxy_protocols = { + "http": "connect", + "https": "connect", + "socks": "5", + "socks5": "5", + "socks4": "4", + "socks4a": "4", +} + +if parsed.scheme not in proxy_protocols: + raise TypeError('unsupported proxy protocol: "{}"'.format(parsed.scheme)) + +def make_argv(): + yield "nc" + if sys.platform == 'linux': + # caveats: macOS built-in netcat command not supported proxy-type + yield "-X" # --proxy-type + # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy). + # Default SOCKS v5 is used. + yield proxy_protocols[parsed.scheme] + yield "-x" # --proxy + yield parsed.netloc # proxy-host:proxy-port + yield sys.argv[1] # host + yield sys.argv[2] # port + +subprocess.call(make_argv()) -- cgit v1.2.3-59-g8ed1b