Many small NAT routers support UPnP these days. If your server machine is behind one of these it is possible for programs to ask the router for the IP addresses of its external interfaces. Most small routers have just one external interface.

This requires that UPnP be turned on in the router, and that you have your computers' software firewall set up to allow UPnP traffic, and that your computer has UPnP Control Point API software installed.

The API comes with Windows (XP later) but it might not be installed. See How to enable the Universal Plug and Play (UPnP) in Windows XP so that you can connect to Games for Windows LIVE. To set up the Windows Firewall see How Windows Firewall affects the UPnP framework in Windows XP Service Pack 2. To turn UPnP on in your router see the router's documentation.


While this is a lot compared to scraping a Web site that returns the client IP that it sees, it should be more stable because your program will not be subject to URL changes and page layout changes.

It also gets you a lot more than just the external IP address. For example you can do port mapping from within your program instead of manually configuring it at the router. This can be more secure because when your program shuts down it can remove any port mappings that it uses, closing the hole.


All of that said, you still need to use the API in your programs. You might look at the PortMapper Class which wraps a few of these API calls in a way that works around a few VB6 issues with unsupported Variant types.