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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Not sure about those methods, but a quick an easy way to determine your external IP is just to visit
Luc FrankenEMEA Server EngineerCommented:
If you can login to your gateway, you should be able to check it there also.

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.
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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.
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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.