How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP???
How To Get Internet IP??? How To Get Internet IP???
How To Get Internet IP???
Go Back  Xtreme Visual Basic Talk > > > How To Get Internet IP???


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2002, 09:15 AM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default How To Get Internet IP???


If I am behind a router, and need to determine my external IP address, that is the IP address which my router uses to connect to the internet, how would I do this?

Lets assume my computer is 192.125.11.4, and my router is 192.125.123.123, how would the first computer at 192.125.11.4, determine the IP address the router is using to connect to the internet.

Please advise
DC
Reply With Quote
  #2  
Old 05-25-2002, 10:34 AM
dcl3500's Avatar
dcl3500How To Get Internet IP??? dcl3500 is offline
Mostly Harmless?

Retired Moderator
* Expert *
 
Join Date: Jun 2001
Location: Western Illinois, USA
Posts: 2,398
Default

If your router has an HTML based control panel like the linksys routers (at least mine does) then you could open the appropriate page in the browser control and parse the page's source to grab the IP address. On the linksys routers the page would be like 192.xxx.xxx.xxx/status.htm
__________________
Don

"So long and thanks for all the fish.'" - Douglas Adams.
Reply With Quote
  #3  
Old 05-25-2002, 02:02 PM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default

Thanks for your reply.

I need to programmatically be able to determine the IP address on all machines which my program is run on.

I cannot guarantee that a client is going to be using a linksys router. What would i do in the case that they have an Asante router or some other brand.

Secondly, to connect to the router, the client would need to know the IP address and Port which the router is using to allow the HTML login to access that Status.html page you mentioned.

Lets assume the user does not know what port the router communicates on for logging in, and also assume that the client has a different router than yourself or I.

In this situation, how can we go about determining the WAN IP?

Please advise.
DC
Reply With Quote
  #4  
Old 05-25-2002, 02:07 PM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

If the router is doing DHCP/NAT, without interfacing directly to the
router, you can't. It is a firewall, and what goes on inside the wall
shouldn't need to know what is going on outside the wall. (I am
not saying your program might not have a good reason for
needing this info, but your program will have to negotiate with the
router for it.)

I guess there might be some kind of server on the internet you
could send a request to and it would return the IP.
__________________
Posting Guidelines
Reply With Quote
  #5  
Old 05-25-2002, 04:14 PM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default

I had considered using some kind of server on the Internet, but the problem with this follows:

1) I would have to host and maintain this server. I would need to make sure that the server never went down or the client apps would no longer work.

2) My ISP constantly changes my IP Address, so I would be unable to run a dedicated server for resolving peoples IP addresses.

Is it possible to have an HTML document with some Scripting determine a users IP address then ship it back via some socket? Im not sure this would work because I think I would need some sort of daemon running at all times. However my thinking is, I could upload a webpage, then instruct my app to connect to that webpage, the webpage would somehow determine the IP address and ship it back to the Visual Basic program. Or I could just make my VB App download that webpage. Im not sure if this would work, or how I should go about dealing with this problem. Any suggestions are welcomed )

NOTE: What's interesting about this. This is a really difficult problem to solve, I have yet to see or find a solution anywhere, I have been doing research on this topic for the last 2 weeks. Everyone I contact is unsure about how to handle this problem. ) I hope someone can help change this )

Thanks for your reply.
Reply With Quote
  #6  
Old 05-25-2002, 04:43 PM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

If you can get some kind of active HTML server that can do ASP,
PHP, or CGI/Perl, then it seems likely that it could be scripted to
return the IP address as a small HTML page. That should be quite
easy to work with. The main problem is getting the server access.
Others have posted in the past about some pretty cheap web
hosting services that support some kind of server-side scripting.
__________________
Posting Guidelines
Reply With Quote
  #7  
Old 05-25-2002, 05:29 PM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default

Interesting, so it seems the only way to solve this problem is using a webserver of some sort.

So it would seem that for every client app i release, I would be responsible for making sure that webserver was running and sending IP address back.

Is there no other way to do this? Its hard to beleive it's so complicated to find your Internet Address.

Please let me know if you think this is the only way to sovle this problem.

Thanks again for your posts.
Reply With Quote
  #8  
Old 05-26-2002, 08:39 AM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

I have prefixed every suggestion based on the idea that your
router is doing DHCP/NAT. Once again, if this is the case, then
your concept of whose internet address is whose is wrong. None
of the client computers connected to the router have an 'internet'
IP address. The only piece of equipment that does is the router.
This means that the client program has to have something to ask.
As has already been said, this means asking the router, or some
web site that sees what IP the router has assigned. Since this IP
only belongs to the router, you can't think there will just be some
automatic way for the client to get access to it.
__________________
Posting Guidelines
Reply With Quote
  #9  
Old 05-26-2002, 09:04 AM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default Thanks for your post

I had a recent conversation with somone on MIRC. They told me that they had encountered the same problem as this a while back.

He told me that it's possible to obtain the routers Internet IP Address using some API call.

He was trying to find the code, but lost it He told me that accessing the Internet would be one way to obtain the IP, but he said it can also be done using an API. How much of that is actually t rue, im not sure.

So lets go with your logic. This means I need to connect to a website. Is it possible to have an HTML webpage using some small script detect the IP address? Or do I need to have a webserver running some IP resolving application?

Please let me know what you would do in this situation.

Thanks again for your post
Reply With Quote
  #10  
Old 05-26-2002, 09:10 AM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

Click. I don't know if it shows the IP you want but, yes, you can use PHP to get your IP.
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #11  
Old 05-26-2002, 09:12 AM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

I can't tell you what I would do because I can't think of a reason
why a program on the inside of a firewall would need this info.
As I already said, that doesn't mean there isn't a reason, but
whatever you try to do with that address will just be getting
around what the router is doing, something that circumvents the
firewall protection that NAT provides.
__________________
Posting Guidelines
Reply With Quote
  #12  
Old 05-26-2002, 09:15 AM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Yes Agent, this is the IP that he would be after.
__________________
Posting Guidelines
Reply With Quote
  #13  
Old 05-26-2002, 09:22 AM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default


So, am I right when I say this:
  • He has been disallowed access to the IP he wants.
  • He wants the IP now.
???
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #14  
Old 05-26-2002, 09:29 AM
ThinkerHow To Get Internet IP??? Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

No, just that he is trying to find a direct way for his program to
get the IP address directly from the router rather than having to
set up a web hosting situation that he would have to maintain for
all his clients.
__________________
Posting Guidelines
Reply With Quote
  #15  
Old 05-26-2002, 10:14 AM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default


Well, you would need a PHP interpreter of some sort to
parse your scripts. Maybe a web hosting service if you
have one (you need a PHP enabled one).

You would use the function GetEnv() to get the
environment variable. To get the host, you would
use the function GetHostByAddr().

PHP Code:
<?
$ip1 = getenv(HTTP_X_FORWARDED_FOR);
$host1 = gethostbyaddr($ip1);

$ip2 = getenv(REMOTE_ADDR);
$host2 = gethostbyaddr($ip2);

Print $ip1 : $host1 || $ip2 $host2;
?>
I think I got that right.
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #16  
Old 05-26-2002, 11:38 AM
Derek Stone
Guest
 
Posts: n/a
Default

I'm fairly sure you can resolve this problem without an external server. It involves the use of the Winsock API, which to many seems daunting, but its far from complicated. Basically what you do is call gethostbyname, which will return a long value that you copy into a HOSTENT structure. The structure will have a list of your IP addresses, one of which will be external. The code below should get you started:

Code:
Dim HostName As String * 256
Dim HostAddress As Long
Dim Host As HOSTENT
Dim HostIP As Long

gethostname(HostName, 256)

HostName = Trim$(HostName)

HostAddress = gethostbyname(HostName)

CopyMemory Host, HostAddress, LenB(Host)
CopyMemory HostIP, Host.hAddrList, 4
Of course this code isn't complete and you'll need to declare all of the structures and API functions.

I'll see if I can find a better example.

Good Luck
-CL
Reply With Quote
  #17  
Old 05-26-2002, 01:31 PM
ChiefRedBull's Avatar
ChiefRedBullHow To Get Internet IP??? ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

If you wana horrible slimy method, simply download http://www.whatismyip.com and parse it out.. eurgh.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #18  
Old 05-26-2002, 01:59 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default


Dag on Chief! What will they think of next!?

http://www.mybackitches.com ???
http://www.ineedfoodhowaboutpizza.com ???
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #19  
Old 05-26-2002, 02:17 PM
ChiefRedBull's Avatar
ChiefRedBullHow To Get Internet IP??? ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #20  
Old 05-26-2002, 06:11 PM
vbtester vbtester is offline
Junior Contributor
 
Join Date: May 2002
Posts: 211
Default Re: whatsmyip.com

Chief, I beleive this would be a good solution if I could be guarentted that they would never change the format of thier webapge. I could parse an HTML document no problem.

But consider what will hapen to my application if they changed their webpage name, style or documentation.

My program would no longer work.

Im hearing a few people say they have solved this problem using API, but its amazing no one knows how to do it I even checked planetsourcecode and they had no code using an API.

If a few people have implemted this, Im dieing to see a working copy. I would be in heaven if someone could show me how to solve this problem with out using a webserver of some sort.

I bow before the human genious who can show me how to use this API
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP??? How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP??? How To Get Internet IP???
How To Get Internet IP???
How To Get Internet IP???
 
How To Get Internet IP???
How To Get Internet IP???
 
-->