Avatar of groone
groone

asked on 

How to get external IP address

Howdy, I have a router on my home network that I am playing with.  I've written some code where I can get all the info on it except the external ip address.  The internal ip is 197.168.0.1 and the inner network is consecutive.  I can get all ip addresses of each connected device, and so now the last thing I want to be able to get is the external ip of my router.  Anyone know how?  I am using VB 6.0

Thank you experts!  
Programming Languages-OtherVisual Basic Classic

Avatar of undefined
Last Comment
g0rath
Avatar of bobbit31
bobbit31
Flag of United States of America image

From: https://www.experts-exchange.com/questions/11813439/Getting-an-internet-IP.html

Comment from aRTie11
Date: 11/10/2000 07:47PM CST
 Comment  


an easy way to make your internet ip appear and not your lan Ip

is to use winsock like so

winsock1.connect "www.microsoft.com",80
InternetIP = winsock1.localip

calling it to access the internet will show the real ip address and not just the lan address

Hope it helps

aRTie11
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

Shell out a ping command and retreive the answers.  The first hop on your list will be the external IP address.
ASKER CERTIFIED SOLUTION
Avatar of g0rath
g0rath

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of vinnyd79
vinnyd79

The first hop on a ping command? Do you mean tracert?
Avatar of bobbit31
bobbit31
Flag of United States of America image

yeah, i think he means tracert:

http://vbnet.mvps.org/index.html?code/internet/tracerthost.htm

your external ip will be the second hop (usually) depending on your network setup
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

Sorry bout that!  yes I meant a tracert.  If this is a standard hom setup, it will generally be the first hop.  If this is at work, especially a large building, that it would not be your next hop.
Avatar of bobbit31
bobbit31
Flag of United States of America image

slight correction:

if it was a standard home setup (e.g., computer to router), it would be the second hop
Avatar of vinnyd79
vinnyd79

I block icmp packets on my firewall so tracert would not work for me.
Avatar of bobbit31
bobbit31
Flag of United States of America image

an extremely kludgy way to do it would be to open www.whatismyip.com and parse the results
Avatar of groone
groone

ASKER

Here is what I did.  Using g0raths idea, I created a file myIP.shtml and added this one line of code
<!--#echo var="REMOTE_ADDR" -->


This showed my external ip address.  Made sure it was the only line in the file and as such I was able to place the ip address into a text field and save it as a file.  Problem solved.
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

Why would it be the second hop?  If it is hooked to say a Linksys, the first hop is the outside of the router.  It doesn't hop to the inside, then the outside.
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

Vinny, do you block ICMP going out as well as coming in?
Avatar of vinnyd79
vinnyd79

Yes.
Avatar of g0rath
g0rath

ah yes, that is a much better way of doing it...but you never know...not everyone has a website laying around they can just put up their own simple IP html page :)
Avatar of bobbit31
bobbit31
Flag of United States of America image

the first hop is from your local machine (your computers network address), the second one is the router
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

That doesn't show up in my tracert.  My hop 1 is my router. (windows xp)
Avatar of bobbit31
bobbit31
Flag of United States of America image

hrmm... weird, on mine (also xp and also on my linux box) the first one is my local ip:

Avatar of g0rath
g0rath

isn't that correct?

a "hop" is the packet that goes from machine 1 to machine 2

So by definition shouldn't hop 1 be

local machine -> NAT reverse proxy --- for most users? as in those that use things like the linksys home firewall/NAT thingy...

my other setup using a linux box as a routher may be different since it reall isn't a "hop" between" the NICs
local machine -> local ip of linux dmz side -> external ip through the other NIC -> the wide open internet

or for networks I've been on are more like this....
local machine -> subnet router -> DMZ router -> Internet GateWay -> wherever....

either way it's not consistant or something not to be relied upon, so it's usually easier to connect to a "trusted" website that can give you back your IP using the environment var REMOTE_ADDR

Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo