Connection with Port forwarding

Started by
3 comments, last by hplus0603 12 years, 10 months ago
Hello

I want to connect to a server behind NAT. So I've forwarded a port on the server and I can access it, but of course only if I know it's external IP. Of course I can look it up here http://www.whatismyip.com/ but I want that you don't have to look it up somewhere. The server should find out his own external IP and thats my problem: how can you do that??? After that the IP is uploaded to an ftp server and the rest is easy.

So how can you find out the IP of the router / external IP??

Or would you approach this problem differently? Is this the normal way to connect with port forwarding??
Advertisement
You can use UPnP to communicate between your app and IGDs (Internet Gateway Devices) on your network. If your router has UPnP turned on, your software can ask it what your external IP is, and also make port forwarding requests.

UPnP involves sending a UDP packet to your IGD to discover its "service URL" (this is usually done either by UDP broadcasting or by using your network configuration's 'gateway' address). After you have the service URL, you send some HTTP+XML requests to the router to request the external IP and/or forward ports.

It's kind of a pain. Most of the UPnP libraries I've used make certain assumptions about a network that aren't always true (such as 'only one router' and 'the local computer hopefully doesn't have Internet Connection Sharing enabled'). Also, some routers don't properly implement UPnP and will break certain library implementations.
Click on the "[color="#0000ff"]Networking and Multiplayer FAQ" link at the top of the forum.

Scroll down to FAQ#9. Read after "There's a number of documents describing how to..." and follow the links. The links are not underlined on my system, so I had to hover over them to find them.
I know that NAT punch-through would be best but I'll start with UPnP that's enough for the moment

Thanks!

I know that NAT punch-through would be best but I'll start with UPnP that's enough for the moment




UPnP is terrible, for several reasons. I generally recommend everyone to turn it off.

First, it is a security problem -- if you have a firewall to keep bad guys in check, but then open up a mechanism for bad buys to punch holes in your firewall, then what good is it?

Second, it's a clunky technical design. For example, what if you have two clients on the inside that both want to control the firewall in the same way? Much better to either require manual configuration (where the user is in control), or to use automatic punch-through, where it "Just works" (at the cost of needing an external matchmaker).
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement