Skip to content

Instantly share code, notes, and snippets.

@eru123
Created July 21, 2023 13:47
Show Gist options
  • Save eru123/df609c9a4572a9427569409bee77fbea to your computer and use it in GitHub Desktop.
Save eru123/df609c9a4572a9427569409bee77fbea to your computer and use it in GitHub Desktop.
@echo off
setlocal EnableDelayedExpansion
set ports=%*
if "%ports%"=="" (
echo Usage: %0 <Local Port 1>:<Server Port 1> [<Local Port 2>:<Server Port 2> ...]
exit /b 1
)
@rem ssh account
set identityfile=%USERPROFILE%\.ssh\id_rsa
set sshusername=root
set sshhost=
set sshport=
set password=
set sshcmd=ssh -i "%identityfile%" -p %sshport% %sshusername%@%sshhost% -N
@rem tunnel ports, append to sshcmd
for %%p in (%ports%) do (
for /f "tokens=1,2 delims=:" %%a in ("%%p") do (
set serverport=%%a
set localport=%%b
set sshcmd=!sshcmd! -L !localport!:localhost:!serverport!
)
)
echo %sshcmd%
call %sshcmd%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment