Last active
December 26, 2022 15:08
-
-
Save johncovv/3fce5a1d1bcfb5ce3fad1f25d79ee17f to your computer and use it in GitHub Desktop.
portproxy wsl2 to localhost
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
# check if you are in administration mode, if not, ask for authorization | |
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
$arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
Start-Process powershell -Verb runAs -ArgumentList $arguments | |
Break | |
} | |
# get wsl intern ip | |
$wsl_host = $(wsl hostname -I); | |
# here you specify the ports for the proxy | |
$ports = @(3000, 3333, 5432, 27017, 3001, 4200, 4201); | |
# reset all interfaces | |
Invoke-Expression "netsh interface portproxy reset"; | |
for ( $i = 0; $i -lt $ports.length; $i++ ) { | |
$port = $ports[$i]; | |
Invoke-Expression "netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$port connectport=$port connectaddress=$wsl_host"; | |
} | |
Invoke-Expression "netsh interface portproxy show v4tov4"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment