Port forwarding is where you connect to a port on a gateway machine and it automatically forwards you to another port on another machine. It can be useful in a very wide range of situations, including bypassing firewalls or redirecting traffic from a public network to a private network (or vice-versa). Combined with lines in your windows\system32\drivers\etc\hosts file you can even redirect where outgoing connections go.

A number of people have asked me to update my trivial port forwarding utility to be a little more user friendly. This is the result. You can download it here and if you want, here's the code.

Apart from its obvious graphicalness, this version allows you to set up any number of port redirections. You can see how many connections are being redirected and you can disconnect them if you feel the need. You can save the redirections you have setup and load them again later.

If you'd prefer the old command line utility, here's the old source code and windows binary.

usage: trivial_portforward [port to listen on] [ip of host to connect to] [port to connect to].

Note: that's ip address, not host name. If you want host names, add your own dns lookup code or use the fancy graphical version.

QuantumG
<< back to my home page


fed says:
great, thanks
Des says:
so great, mucho thanks!!!

I have a question. How many threads (connections) this module can handle?
And how can I start this as windows service?
KolobocK says:
thanks for code!
but trivial sources and binary are not available :(
also could you please put here header file for portforward.cpp (portforward.h)? [oops, done].
Hector Garcia (hec50@hotmail.com) says:
This program is pretty cool, but I tried to use it over Windows Xp 64 bits and it didnīt work, do you know any other program like this that works over Xp 64 bits? Thanks in advance...
QuantumG says:
I use it on xp64, no problems.
xerces8 says:
The gui version fails on my WinXP 32bit too. The CLI versions works thou
Jon Ashley (jonathan.ashley@ praxis-his.com) says:
That's a really nice little tool! It looks as though it might solve a problem for me. Can you please tell me what licence it is under? Thanks.
Albert Bloomfield says:
I think you should be calling shutdown() in your code somewhere. Anyway it didn't work right for me until I put in some calls to shutdown() before you close the sockets.
Troy says:
is there a way to specify which local ip to use if the system has multiple?
Pedro says:
Around portfoward.cpp:660, function dnslookup(), the line
return (a << 24) | (b << 16) | (c << 8) | d; // network order
I think that should be:
return (d << 24) | (c << 16) | (b << 8) | a;
foo says:
test
thirdwheel says:
Hey, great tool, thanks. One problem though, I have it route requests to a port (say, 8123) to port 22 of a VM (ip address 192.168.0.5) - I can connect to it directly but not through the tunnel entry. It registers the connection but when it tries to connect, it times out. I'm running Windows XP SP2. The VM is attached to an MS Loopback adapter.
thirdwheel says:
I just tried the command line tool, and it worked fine... wtf
thirdwheel says:
Hey, what did you use to compile this? I compiled it using mingw and it came out 18k smaller... and that was with static linking...
thirdwheel says:
hey Troy, I've made a change to the command line version of this program that allows you to specify an IP address. If you have mingw, you can get the patch at http://milo.thats-too-much.info/patches/trivial_portforward-sourceip.patch - GUI version change to come
thirdwheel says:
I found the problem with the GUI version. Windows Firewall needed an exception to let it in.
Gary Holmes says:
Is this suppose to forward ports on a router? I had my friend who has a router try it (on Vista) and it didn't work. Thanks.
Theo says:
Just wanted to say Pedro's comment above is correct. Network order means less significant byte first, so you should have (d << 24) | (c << 16) | (b << 8) | a. That's why it doesn't work for some - if you enter a host name, the address is given by the winsock library, but if you enter an ip, it is miscalculated when trying to connect.
QuantumG says:
Thanks Theo, should be fixed now.
Anonymous says:
Hello,
is it possible that I can use it as Windows service.. I have a Win 2003 Server and I would like to make some port forward to local PCs and I would like that the program would be started automatically when you restart the PC
QuantumG says:
Learn to code, I'm not your bitch.
Anonymous says:
I had a problem to access a site and only vpn connection on other pc(same LAN) was able to access that. this tool works fine for this situation.
anti says:
Is it possible for you to provide a .zip file for the trivial port forward command line tool instead of just the cpp file?
QuantumG says:
Just compile it with:

cl.exe trivial_portforward.cpp ws2_32.lib

Or, make a standard console application project and copy the code in. You should be able to figure that out.
Anonymous says:
GREAT!!!
Anonymous says:
a question: the GUI accepts command line parameters? i.e. useful for autorun...
canty says:
Simple to use, effective and powerfull. Thanks a lot!!!
vad says:
THE BEST!!! THNX!
Anonymous says:
tnx!
Accio says:
Damn that's awesome! THANKS
Mike G says:
Hello,
is there a way to send real ip to forwarded port coz it shows up forwarders ip on destination
el-Barto says:
Hey Mike,
that's what it is for. (And also the reason I got this cool tool in the first place)
And QuantumG; Thanks, great Tool!
sdd says:
dff
iwantantono says:
windows 2000 server cannot run this program why. can u tell me.
in not good in english

Gang says:
Great tool! Thanks.
Lanti says:
i don't get how to port forwarding for turkojan
any tutorial :S please
Lanti says:
i don't get how to port forwarding for turkojan
any tutorial :S please
Mungo says:
I love small programs like this one ... works fine
Tim says:
This is a great tool! Works so easily! Thanks!
Nir says:
Great !!!!
(saved my butt during a night work .. :) must not tell security I ever used it)
KG says:
Great tool, good work!
szabi says:
Having parameters would be nice, like the name of the file to be loaded - pretty useful though :)
MGP says:
Ah, finally a port forwarder that just works _O_

All of them are either payware, buggy like shit or loaded with stuff I don't need. Though, maybe you can change the 'Stopped' status thing, I spent 10 minutes looking how to turn it on until I discovered you just need to open a connection :P

Btw, add a Paypal donation button, I'll use it
coobic says:
Listen with specicifed address is required. Please :)
qryzhephenetour says:

thirdwheel says:
I've got specific address for the command line tool - I just need to recreate the patch.

As for the GUI tool - that's coming.
layhesisoma says:

psychtasunmibo says:

chisabodotsto says:

cocksovibreiwai says:

Michael says:
Thank you! you saved my day:)
deuverlopider says:

Anonymous says:
Yuck..!
Port Forwarding is a virus guys....
Mr Scotty says:
Looked @ the port forwarder and have some suggestion to improve it.
First a small bug
When you have 2 or more forwards saved and you load them only the first is loaded. and the destionation port has the next localport concatenated
Solution put a \\n after each line you save.

Improvements:
1. I used it in combination with UltraVNC and had some performance degradation. (as happens with other forwarding tools also)
To have a better performance i increased the send and receive buffers and i set TCP_NODELAY (as UltraVNC does). For the application it would be nice to have this configurable for each redirection. Maybe also an application wide default.

2. Have a default configuration which is loaded when you start the application.
3. Run it as a service so you don't need to login to have it working
4. When minimized have a tray icon and start it minimized (option?)
5. As suggested before have a parameter telling which settings to load.

Hope you can use the suggestion to make this GREAT tool even beter.
Thx for sharing it with the rest of the world.


Marco says:
Nice, Nice!

Would be cool if we can start the tool with a file parameter, so that it automatically loads the *.txt config file. That gives us the possibility to use it in the autostart-function of windows
anon says:
Would be nice, but it seems to have a maximum packet size (or some bug), so it just breaks too long request replies. :(
ankara says:
Fixed save_redirs function. Apply the following change:

- sprintf_s(buf, sizeof(buf), "%i %s %i", info->lport, info->dest_host, info->dport);
+ sprintf_s(buf, sizeof(buf), "%i %s %i\\n", info->lport, info->dest_host, info->dport);

ankara says:
Oups.. In the previous post make sure to use just one backslash.. forum added the second one.
ankara says:
Don't bother using this tool. Use netsh.exe. It is standard, and works!

netsh
netsh > interface portproxy
netsh interface portproxy > add v4tov4 listenport=8080 connectaddress=192.168.1.28 connectport=8080

That's all! :)
Anonymous says:
it crashes for me

Anonymous says:
but thx ;-)
MJ from Spain says:
I imagine the gui interface can't load configuration file from command line; I tried to recompile it but had problems importing project with WxDev-cpp. I had to recompile trivial_portforward.cpp for win2000 as downloaded binary used too much resources and was hunging the system. Recompiled exe works just fine. Great tool!! thanks a lot.
Daniil Harik says:
Working fine on Windows 7 :)

Thank
bethanntub says:
I have read a good joke in internet ;) How do you get holy water? Boil the hell out of it.
___________________________
vpxl
namsoo jeon(namsoo.jeon@samsung.com) says:
Thanks. It is very useful program to me. Can you please tell me what licence it is under? I'd like to use this program to our program.
Joonas says:
Thank you for this simple yet useful tool
developer says:
f-secure says it has a trojan in it.

You're just not creative enough to understand.
Your name: