Solved

How to get external IP address

Posted on 2004-03-25
19
9,611 Views
Last Modified: 2013-11-13
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!  
0
Comment
Question by:groone
  • 6
  • 5
  • 4
  • +2
19 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10680338
From: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11813439.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
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10680404
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 10680407
Shell out a ping command and retreive the answers.  The first hop on your list will be the external IP address.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Accepted Solution

by:
g0rath earned 500 total points
ID: 10680430
create a form

add a label, command box, and the Microsoft Internet Transfer Control 6.0

Then add this code

Option Explicit

Private Sub Command1_Click()
    Dim Data As String
    Data = Inet1.OpenURL("http://www.showmyip.com/simple/")
    If Not Inet1.StillExecuting Then
        Label1.Caption = Left(Data, InStr(Data, " ") - 1)
    End If
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10680438
The first hop on a ping command? Do you mean tracert?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10680460
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
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 10680578
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.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10680635
slight correction:

if it was a standard home setup (e.g., computer to router), it would be the second hop
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10680683
I block icmp packets on my firewall so tracert would not work for me.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10680752
an extremely kludgy way to do it would be to open www.whatismyip.com and parse the results
0
 
LVL 3

Author Comment

by:groone
ID: 10680962
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.
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 10680964
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.
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 10680970
Vinny, do you block ICMP going out as well as coming in?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10680996
Yes.
0
 
LVL 5

Expert Comment

by:g0rath
ID: 10681020
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 :)
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10681088
the first hop is from your local machine (your computers network address), the second one is the router
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 10681130
That doesn't show up in my tracert.  My hop 1 is my router. (windows xp)
0
 
LVL 18

Expert Comment

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

0
 
LVL 5

Expert Comment

by:g0rath
ID: 10681280
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

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 145
Not needed 13 119
Problem to error 4 67
troubleshoot a python script 8 24
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

837 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