Retrieve gateway's internet IP

Let's asume a LAN with some windows machines, one of
it with the IP is connected to the internet via a gateway with
the LAN IP
The ISP assigned the IP to the gateway.

My question is:
Do you know a way using winsock or iphlpapi to retrieve
this last IP? I tried GetIpForwardTable and
GetBestRoute but those functions just give me the
gateway's LAN IP.

Thanks in advance!
Who is Participating?
The external IP is not in your computer, it's only defined on the gateway. You have to make an external call to it to get it (if it supports this, which I doubt) or use some other external source (as parsing the HTML page as discussed above).
Not sure about those methods, but a quick an easy way to determine your external IP is just to visit
LucFEMEA Server EngineerCommented:
If you can login to your gateway, you should be able to check it there also.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Last_InquisitorAuthor Commented:
You are both right. Of course there are many ways to
check that IP MANUALLY. But I'm looking for a way to
get it in one of my programs. I want to code a function

const char* GetExternalIP(const char *gateway_lan_ip);

I already thought of visiting a service like whatismyip,
retrive the HTML page and parse it to get the IP.
But I want to avoid using external services.
Perhaps you can pull that info from the registry:

Search for DefaultGateway or DhcpDefaultGateway depending on whether you use DHCP or not to determine the exact location of the setting.
Last_InquisitorAuthor Commented:
This won't work. It will just lead me to the gateway's LAN IP, not
its external IP. Retrieving the LAN IP is not a problem at all, but it's
not what I want.
Thanks anyway.
Last_InquisitorAuthor Commented:
#?&*% grummel!
I feared it...
Well, thanks to all of you, especially jlindq for
taking away all illusions...
heres an intresting one
form a dos prompt, type do


the first ip address will be your own gateway, the second listed will be the isp's gateway
See if your router supports SNMP and you can usually grap the info you want that way. SNMP can be very powerful when used correctly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.