add SSH tunneling script
This commit is contained in:
parent
c4fa529183
commit
a0b1a995f6
1 changed files with 17 additions and 0 deletions
17
sshtunnel.sh
Executable file
17
sshtunnel.sh
Executable file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue