Retrieve gateway's internet IP

Let's asume a LAN with some windows machines, one of
it with the IP 10.1.1.1.
10.1.1.1 is connected to the internet via a gateway with
the LAN IP 10.1.1.254.
The ISP assigned the IP 80.142.23.56 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!
LVL 1
Last_InquisitorAsked:
Who is Participating?
 
jlindqCommented:
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).
0
 
techwiz330Commented:
Not sure about those methods, but a quick an easy way to determine your external IP is just to visit http://www.whatismyip.com.
0
 
LucFEMEA Server EngineerCommented:
If you can login to your gateway, you should be able to check it there also.

LucF
0
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
like

const char* GetExternalIP(const char *gateway_lan_ip);

techwiz330:
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.
0
 
JFrederick29Commented:
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.
0
 
Last_InquisitorAuthor Commented:
JFrederick29:
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.
0
 
Last_InquisitorAuthor Commented:
#?&*% grummel!
I feared it...
Well, thanks to all of you, especially jlindq for
taking away all illusions...
0
 
hypomarcCommented:
heres an intresting one
form a dos prompt, type do

tracert 158.152.1.58

the first ip address will be your own gateway, the second listed will be the isp's gateway
0
 
wickedzCommented:
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.
0
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.