summaryrefslogtreecommitdiff
path: root/.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py
diff options
context:
space:
mode:
authorPedro Pereira <pedro.hr.pereira@proton.me>2026-10-16 15:19:13 -0300
committerPedro Pereira <pedro.hr.pereira@proton.me>2026-10-16 15:19:13 -0300
commit1eb69e9a795cc19450178c07d8d382622bc7ad70 (patch)
treeb6bc60605044fe929986f31b3b6bf4fee9b56e14 /.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py
first commit
Diffstat (limited to '.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py')
-rwxr-xr-x.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py37
1 files changed, 37 insertions, 0 deletions
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..4b692f9
--- /dev/null
+++ b/.config/zsh/oh-my-zsh/plugins/shell-proxy/ssh-proxy.py
@@ -0,0 +1,37 @@
+#!/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 in {'linux', 'cygwin'}:
+ # caveats: the built-in netcat of most linux distributions and cygwin support proxy type
+ # 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())