Last active
April 11, 2021 21:29
-
-
Save nauhygon/f87ebf4e1d74691c7730bab4edeedd92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Func: Start an SSH tunnel (autossh) to a server $1 and map it to a | |
# local port $2 (default to 8888), which can be used as a SOCK. Start | |
# a HTTP proxy server (polipo) with proxy port $3 (default to 8123) | |
# and point it to the SSH tunnel. | |
# | |
# See also: | |
# autossh (http://www.harding.motd.ca/autossh/) | |
# polipo (https://www.irif.univ-paris-diderot.fr/~jch/software/polipo/) | |
# | |
# Usages: | |
# stun [email protected] | |
# stun [email protected] 8080 7777 | |
# | |
# Note: | |
# You must make sure you can ssh to the remote host passwordlessly | |
# first. To make this happen, simply do this on your local host. | |
# ssh-keygen # No passphrase | |
# ssh-copy-id [email protected] | |
# And now you should ssh to the host without being asked to enter a | |
# password. | |
# ssh [email protected] | |
# | |
function stun() { | |
if [ -z $1 ]; then | |
echo "${FUNCNAME}() requires at least one parameter, `server`." | |
fi | |
server=$1 | |
tunnel_port=$2 | |
if [ -z $tunnel_port ]; then | |
tunnel_port=8888 | |
fi | |
proxy_port=$3 | |
if [ -z $proxy_port ]; then | |
proxy_port=8123 | |
fi | |
# Restart ssh & autossh | |
killall -q ssh | |
killall -q autossh | |
#ssh -o TCPKeepAlive=yes -o ServerAliveInterval=50 -f -C -D 127.0.0.1:${tunnel_port} ${server} -N | |
autossh -M 0 -f -o TCPKeepAlive=yes -o ServerAliveInterval=50 -f -C -D 127.0.0.1:${tunnel_port} ${server} -N | |
# Restart polipo | |
killall -q polipo | |
polipo daemonise=true socksParentProxy=127.0.0.1:${tunnel_port} proxyPort=${proxy_port} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment