Solved

Retrieve gateway's internet IP

Posted on 2003-10-26
9
593 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
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:Luc Franken
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
 
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now