Skip to content

Instantly share code, notes, and snippets.

@SirJson
Last active June 9, 2020 20:17
Show Gist options
  • Save SirJson/1b0ae650b1e826389760eec9532d047d to your computer and use it in GitHub Desktop.
Save SirJson/1b0ae650b1e826389760eec9532d047d to your computer and use it in GitHub Desktop.
Ad-hoc Tunnel and Proxy Commands for PowerShell 6+ and Windows 10 >= 1809
# This version uses my Write-RGB function that can be found in another Gist or maybe one day as a installable Module...
# See below for a colorless version
function tunnel {
param (
[string]$Url,
[int]$RemotePort,
[int]$LocalPort,
[string]$RemoteProfile
)
Write-RGB "Opening SSH tunnel from {fg:#0000ff}localhost:$LocalPort{clc} to {fg:#00ff00}${Url}:$RemotePort with Profile {fg:#FF5722}$RemoteProfile"
ssh -f -N -L "${LocalPort}:${Url}:${RemotePort}" $RemoteProfile
}
function proxy {
param (
[string]$sshprofile,
[int]$port = 9000
)
Write-RBG "Starting local SOCKS5 proxy using SSH profile {fg:#FF5722}$sshprofile{clc} at Port {fg:#00aaaf}$port{clc}"
ssh -N -D $port $sshprofile
}
# This is the same version just without color output
function tunnel {
param (
[string]$Url,
[int]$RemotePort,
[int]$LocalPort,
[string]$RemoteProfile
)
Write-Host "Opening SSH tunnel from localhost:$LocalPort to ${Url}:$RemotePort with Profile $RemoteProfile"
ssh -f -N -L "${LocalPort}:${Url}:${RemotePort}" $RemoteProfile
}
function proxy {
param (
[string]$sshprofile,
[int]$port = 9000
)
Write-Host "Starting local SOCKS5 proxy using SSH profile '$sshprofile' at Port $port"
ssh -N -D $port $sshprofile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment