Solved

Retrieve gateway's internet IP

Posted on 2003-10-26
9
577 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:Last_Inquisitor
Comment Utility
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
Comment Utility
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
Comment Utility
#?&*% grummel!
I feared it...
Well, thanks to all of you, especially jlindq for
taking away all illusions...
0
 

Expert Comment

by:hypomarc
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The DSL Parameters part of this article is valid and can be considered with any brand of internet router and modem (Dlink, 3com, Alcatel, Usrobotics, Parks), by accessing the configuration interface available by the manufacturer eg: http://10.1.1.1 …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

12 Experts available now in Live!

Get 1:1 Help Now