diff options
author | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
---|---|---|
committer | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
commit | edc449275b6c04445f58b108ca0937a87c1e8430 (patch) | |
tree | 9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/shell-proxy/ssh-proxy.py | |
parent | 6f5424ca96c4221ef433f545642669e9c104d0ed (diff) |
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/shell-proxy/ssh-proxy.py')
-rwxr-xr-x | oh-my-zsh/plugins/shell-proxy/ssh-proxy.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py b/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py new file mode 100755 index 0000000..a498c84 --- /dev/null +++ b/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()) |