Or: “Setting a portproxy”, or: “i need an easy tool to manage my portproxies”
So, i’ve been developing a web app and wanted to use a second computer for debugging in chrome, mainly because i don’t have a second screen and i figured a tablet floating next to my display would suffice.
I broke a lot of network settings and enabled a lot of firewall rules trying to connect to a port on my host pc from the tablet, nothing worked and i really got frustrated.
A good friend of mine was kind enough to point me to “netsh interface portproxy” and the possibility to set portproxies in windows to forward connections from and to my apps.
Trying out a lot of combinations i cluttered my portproxies and had to figure out how to delete them one-by-one.
It turned out that it’s pretty easy to just set up a portproxy for the same external and internal port and the local network:
netsh interface portproxy add v4tov4 listenport=[YOUR-PORT] listenaddress=0.0.0.0 connectport=[YOUR-PORT] connectaddress=127.0.0.1
Now, i’m a pretty lazy person when it comes to tedious-typing tasks in the command-line and i really didn’t want to delete the 10 broken portproxies created while trying out different things with the netsh interface portproxy add command.
So i went ahead and wrote a small powershell script that helps me keep oversight of my setup and enables me to easily delete and create new portproxies.
It’s far from perfect, but it’s easy to use, reliable enough and you can upload it to github.
Write-Host THIS SCRIPT WILL ONLY WORK IF YOU RUN IT WITH ELEVATED PRIVILEGUES! Write-Host List of set proxies: Write-Host #################### netsh interface portproxy show v4tov4 Write-Host #################### $rord = Read-Host -Prompt 'Do you want to create a new proxy (1) or delete a proxy (2)' if($rord -eq 1) { Write-Host [1] Create PortProxy $local = Read-Host -Prompt 'Do you want to open a port to the local network? (listenaddr 0.0.0.0, connectaddr 127.0.0.1, same listen and connect port), type (yes)' if($local -eq 'yes') { Write-Host [YES] Opening port to local network, set listenaddr = 0.0.0.0, connectaddr 127.0.0.1 $port = Read-Host -Prompt 'Please input the port that you want to open to the network' netsh interface portproxy add v4tov4 listenport=$port listenaddress=0.0.0.0 connectport=$port connectaddress=127.0.0.1 Write-Host 'Done, press any key to exit' pause exit } Write-Host [NO] Opening port with full manual settings, you will need to enter the listen port, listen addr, connect port and connect addr. $lport = Read-Host -Prompt 'Input port to listen to' $laddr = Read-Host -Prompt 'Input address to listen to' $cport = Read-Host -Prompt 'Input port to connect to' $caddr = Read-Host -Prompt 'Input address to connect to' netsh interface portproxy add v4tov4 listenport=$lport listenaddress=$laddr connectport=$cport connectaddress=$caddr Write-Host 'Done, press any key to exit' pause exit } if($rord -eq 2) { Write-Host To delete a portproxy, you will need to enter the listen port and listen address $lp = Read-Host -Prompt 'Enter the port of the proxy you want to delete, you will enter the listenaddress in the next step' $la = Read-Host -Prompt 'Enter the listenaddress of the proxy you want to delete' netsh interface portproxy delete v4tov4 listenport=$lp listenaddr=$la } Write-Host Done pause exit
You’ll probably have to create a loop outside the script if you want to do more than one thing per session, this was enough for my use-case and i left it be.
Alternatively, i found “PortProxyGUI” from “zmjack” on github. It’s nice!
Edit:
Trouble running the script because execution of powershell scripts is disabled on your system?
Enjoy and have fun!
Leave a Reply