diff --git a/sshtunnel.sh b/sshtunnel.sh new file mode 100755 index 0000000..8b90ae0 --- /dev/null +++ b/sshtunnel.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Allows to access some web UIs through VPN + +function sshtunnel { + target=$1 + + # get occupied ports by SSH sessions + local_used_ports=$(lsof -PiTCP -sTCP:LISTEN | grep ssh | awk -F':' '{print $2}' | uniq | grep -Eo '[0-9]{1,5}') + + # define a port + local_selected_port=$(shuf -n 1 <(seq 60000 | grep -Fxv -e{$local_used_ports})) + + echo "$target: https://localhost:$local_selected_port" + ssh -L $local_selected_port:$target:443 oli@10.7.1.90 +} + +sshtunnel $1