Advertisement

Retrieving IP through router?

Started by June 22, 2006 07:22 AM
3 comments, last by Tom 18 years, 8 months ago
Hi there. I'm designing the network component of my engine, and one of the first problems that occurred to me was retrieving the host Internet IP from a router. If you're familiar with routers, you know they assign a local IP (192.168.*) to each client on the network, or else you can configure the IP manually. Either way, the Internet IP is not immediately available to any client on the network unless you query the router (e.g., open up the homepage) or go to a site/server on the Net that will bounce your IP back at you. I want to be able to detect the local machine's Internet IP that was issued to the router, not the local IP the router provides. The obvious solution is to query the router's IP list using its hostname. Unfortunately — and I don't know if this applies to most/all routers or just the one I'm using — it returns an error: "Authoritative answer host not found." If I query the DNS table using the router's local IP (192.168.1.1), it returns the host name "dslrouter." I then use this name to retrieve a list of IP's, and it gives me the error above. So, my question is, can I get around this? Is there a protocol for communicating with routers or other such devices that will let me retrieve the assigned INet IP? I really appreciate any help on this. Thanks in advance.

GDNet+. It's only $5 a month. You know you want it.

Read Q18 in the Multiplayer forum FAQ for the answer.

However, it's not a good idea, and you should never normally need to.

Mark
Advertisement
You can use upnp. Most p2p filesharing programs do this as well. Your router should support it though. Maybe something to add in the FAQ.
UPnP is such a bad idea.

1) It's a security hole -- what if MYWORM.EXE wants to open a hole in your firewall? Would you want that?

2) What if two different machines behind the firewall want to use the same port?

It's much better to design your program to correctly support NAT traversal.
enum Bool { True, False, FileNotFound };
Thanks for the help, guys. Unless there's an easy way to do NAT traversal on a Windows box — doesn't seem to be based on what I've read — I'll have to bounce my IP's back and forth. Not really a big deal; I only need the client's IP, which the server can be trusted to return correctly. Thanks again.

GDNet+. It's only $5 a month. You know you want it.

This topic is closed to new replies.

Advertisement