Solved

Retrieve gateway's internet IP

Posted on 2003-10-26
9
622 Views
Last Modified: 2012-05-04
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!
0
Comment
Question by:Last_Inquisitor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:techwiz330
ID: 9624605
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
 
LVL 32

Expert Comment

by:LucF
ID: 9625598
If you can login to your gateway, you should be able to check it there also.

LucF
0
 
LVL 1

Author Comment

by:Last_Inquisitor
ID: 9626118
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:JFrederick29
ID: 9626598
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
 
LVL 1

Author Comment

by:Last_Inquisitor
ID: 9626633
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
 
LVL 2

Accepted Solution

by:
jlindq earned 250 total points
ID: 9626826
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
 
LVL 1

Author Comment

by:Last_Inquisitor
ID: 9626871
#?&*% grummel!
I feared it...
Well, thanks to all of you, especially jlindq for
taking away all illusions...
0
 

Expert Comment

by:hypomarc
ID: 9646398
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
 
LVL 1

Expert Comment

by:wickedz
ID: 9647849
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

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Suggested Courses

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question