dotfiles/scripts/tunnel
2017-02-12 13:13:09 +01:00

25 lines
607 B
Bash
Executable file

#!/usr/bin/env bash
# Dynamically determines if the ssh connection
# is to be proxied through `proxytunnel`
# To be used with ssh_config ProxyCommand
host="$1"
port="$2"
if [ -z "$http_proxy" ]; then
nc "$host" "$port"
else
proxy=$(echo "$http_proxy" | sed 's/^https\?:\/\///' | sed 's/\/$//')
port=443 # Most won't want this
echo "$proxy" | grep '@'
if [ $? == 0 ]; then
user=$(echo $proxy | cut -d '@' -f 2)
proxy=$(echo $proxy | cut -d '@' -f 1)
proxytunnel -p $proxy -P $user -d $host:$port
else
proxytunnel -p $proxy -d $host:$port
fi
fi