Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address
Getting The Internet IP Address Getting The Internet IP Address
Getting The Internet IP Address
Go Back  Xtreme Visual Basic Talk > > > Getting The Internet IP Address


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2010, 10:54 PM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default Getting The Internet IP Address


Ok, I have been looking for a proper solution for a long time. Today I have finally given in and am finally asking for help.

What I have found is a lot of "say" how to do it and really tried my best, but never properly have been able to get the correct address.

I know winsock.remoteIP doesn't return an internet ip address when a router is involved. I tried WMI, and just couldn't figure it out. I also tried adapter info, and for whatever reason still got different addresses. Finally I was able to use Inet, and get the ip address from a web url.

However, I don't believe this is proper. What if the web address doesn't exist anymore? What if the address has something malicious on it? I would prefer to do this a proper way. I've been searching the forums and just can't find it ... tried yahoo, google, youtube...
__________________
ZaCkO ... Who is your attitude?

Last edited by ZaCkOX; 05-25-2010 at 11:01 PM.
Reply With Quote
  #2  
Old 05-26-2010, 07:31 AM
vb5prgrmrGetting The Internet IP Address vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

This looks promising but did not test... http://www.vbcode.com/Asp/showsn.asp?theID=13062
(see small box above large box for the code as it looks like a faulty submission)



Good Luck
__________________
Just because I'm an expert does not mean I know it all and just because I know it all does not mean I'm an expert
Reply With Quote
  #3  
Old 05-26-2010, 11:20 AM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default Thanks vb5prgrmr but no luck :(

I still only see my private ip address (router connected). I read I could tap into the router, if no password was used and retrieve the internet ip that way, but again I don't feel this is right. I am wondering how the web urls are getting the internet ip? Maybe they only get it after a connection has been established... if so, I could connect to my server first but I still don't know how to find the internet IP if a router is involved.

UPDATE:

Well I did some more research and found out the reason why this have been difficult. Windows XP doesn't have the internet ip address, the router does. All I can parse out would be a private ip address when a router is connected. For me to solve this, I would have to connect to a url, and parse out the internet ip address then.
__________________
ZaCkO ... Who is your attitude?

Last edited by ZaCkOX; 05-26-2010 at 03:40 PM.
Reply With Quote
  #4  
Old 05-29-2010, 08:09 PM
dilettante's Avatar
dilettanteGetting The Internet IP Address dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,529
Default

Actually if (1.) your router supports UPnP, (2.) you have this option turned on in the router, and (3.) your software firewall on the PC is set to permit UPnP traffic though... there is a way to do this without fetching an HTML page and parsing it and it is standard across compliant routers.

You can also do a number of other things, for example setting and deleting port mapping ("port forwarding") rules.


There is a COM helper DLL for doing this in XP and later versions of Windows.

Sadly this requires the use of COM callbacks, since the DLL does not support VB6-style events. Even more sadly the version of the DLL that ships in WinXP doesn't expose the Type info needed to handle the callbacks (though I've confirmed Vista does).

There are three possible fixes: (1.) develop and compile under Vista, (2.) develop and compile under WinXP using a typelib I made to provide the necessary type info, or (3.) use VBScript-style event binding, which VB6 doesn't support naturally but you can work around.

One more glitch is that calling some methods from VB6 requires that you pass Variant values of subtype UInteger and ULong. I have a hack to get around this too.


To make this simple to use I have created a Class that wraps a subset of the DLLs functionality. This is limited enough that you don't need the full COM callback support, so compiling under XP is possible by using the VBScript event binding method. I call it PortMapper, and I've isolated the callback logic to a helper class called PortMapperCBs.

Once you have called PortMapper.OpenMapper() and received it's Opened event with Success = True some properties are available:
PortMapper.ExternalIP
Portmapper.InternalIP
You can also call two methods:
PortMapper.Add()
PortMapper.Remove()
These let you add and remove port mappings through the router. When done you should call:
PortMapper.CloseMapper()

I'll probably combine the two Classes at some point. They really should not have to be separate, it was just done because I was recycling some old code.

On top of this you may well want to add logic to add a Windows Firewall exception for your program, as well as remove it upon exit. Ideally you'd do this as part of program installation, but for hacking around this is fine. The required code and helper DLL are kicking around the Web so I didn't bother to include this in my PortMapper. I might also reconsider that at some point.


None of these requires admin rights on the PC or on the router. I can run my programs using PortMapper and opening a firewall exception under Vista without elevation.
Reply With Quote
  #5  
Old 05-29-2010, 08:28 PM
dilettante's Avatar
dilettanteGetting The Internet IP Address dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,529
Default

Attached Images
File Type: png sshot.png (6.6 KB, 7 views)
Reply With Quote
  #6  
Old 05-29-2010, 11:36 PM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default Thank you! :)

This is perfect, it has a few errors but I think I can figure out it. Great! Shows my correct internet IP :P
__________________
ZaCkO ... Who is your attitude?
Reply With Quote
  #7  
Old 05-30-2010, 08:08 AM
dilettante's Avatar
dilettanteGetting The Internet IP Address dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,529
Default

I hope it helps.

When getting errors first be sure you have the UPnP exception checked (on) in Windows Firewall and make sure UPnP is enabled in the router.

Then be sure you have the right compile-time variable setting to allow it to compile properly. I.e. in PortMapperCBs set #Const XP_COMPILE = True and also comment out the Implements statment if you are on an old OS (WinXP). Also you might double check that in PortMapperCBs the IDispatchCallback method is set as the default method of the Class.
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
Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address Getting The Internet IP Address
Getting The Internet IP Address
Getting The Internet IP Address
 
Getting The Internet IP Address
Getting The Internet IP Address
 
-->