Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display IP address (Public and Private) 3

Status
Not open for further replies.

NTesla1886

Technical User
Mar 14, 2008
62
US
I need to write a program that will display both your public and private IP address and whether the private is Static or dynamic.

How would I go about this or is it even possible in VB 6.

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
>is it even possible in VB 6

Indeed it is. And a quick keyword search in this forum should find you a number of posts on the subject.

If you can't find them, let us know and we'll see what we can do to help
 
Had one thread handy... for public IP, see thread222-1315879. Several solutions in it, including a link to strongm's solution using the INet control.

 
I have figured out how to get my local IP. I am working on trying to get my Public IP. How can I determine if it is Static or Dynamic.

When I use the following code, I get invalid procdeure call or arguemment. I copied the code from the following form as posted by waytech2003:


Private Sub Form_Load()
WebBrowser1.Navigate ("End Sub

Private Sub WebBrowser1_TitleChange(ByVal Text As String)
Me.Caption = Right(Text, InStr(Text, " ") - 2)
End Sub

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
Interesting... I didn't know that whatismyip.com added an "automation page" to their site, so you should use that instead.

Automation page link:

Explanation:

With a slight mod to my code in that page, sHTML will contain a few html tags surrounding the public IP.

Code:
Private Sub Form_Load()
   WebBrowser1.Navigate ("[URL unfurl="true"]http://www.whatismyip.com/automation/n09230945.asp")[/URL]
End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
   Dim sHTML As String
   sHTML = WebBrowser1.Document.documentElement.InnerHTML
   'parse sHTML, finding the part that contains your public IP address
End Sub
 
I didn't now that they'd done that either. Neatly simplified my Inet solution (and completely gets rid of the RegExp part ...)
Code:
[blue]Private Function getExternalIP() As String
    getExternalIP = Inet1.OpenURL("[URL unfurl="true"]http://www.whatismyip.com/automation/n09230945.asp")[/URL]
End Function[/blue]
 
StrongM

When I use your code I get variable not defined on Inet1. I have references to Microsoft VBScript Regular Expression 1.0 and 5.5

I am using VB 6 SP6

gaitarzan
You code works great but how can I put the IP into a text box.

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
>I have references to Microsoft VBScript Regular Expression 1.0 and 5.5

You don't need them for this simplified version.

>a reference to Microsoft Internet Controls

No. As my original example states:
strongm said:
' Assumes you have an Internet Transfer Control on your form
So not just a reference, and not the Microsoft Internet Controls
 
gaitarzan

I now know how to get the ip to a text box but the ebBrowser1_NavigateComplete2 never executes. I moved the code in this sub to the form load and I get a object variable or with block not set error on the shtml = line.

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
Not sure why the event isn't firing, but... strongm's code is the way to go on this one.
 
I got his to work. I was just looking at another option. It is not really important.

Thanks any way

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
Ok I have just had the client add some more info. I need to add everything that ipconfig /all reveals. It also needs to run with out having to be installed.

Currently what I have will display the public and private IP address's as well as the system name but it needs to be installed

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
>everything that ipconfig /all reveals

This is doable, but

>It also needs to run with out having to be installed.

What, precisely, does your client mean by this?
 
VB isn't the best way to go for standalone applications - but, with certain restrictions, it can be done.

First thing to realise is that VB absolutely requires a number of runtime DLLs in order to run. They are so vital to VB6 applications that Microsoft kindly include them in the OS - so you don't actually need to install them for your app.

So, what this means is that as long as your application only uses the standard VB controls (the ones that appear by default in the General tab of the components toolbox) and does not use any ActiveX libraries beyond the default ones to be found under References, then you can compile your program to an EXE file and run it standalone.

What that means with THIS program is that you won't be able to use the Internet Transfer control. Nor can you use the Internet Controls (although with a small bit of work you can access the required functionality of the Internet Controls as a library instead - and the library is handily one of the files that should exist on any machine that has Internet Explorer on it)

As for getting all the ipconfig info, well you might like to have a look at WMI, specifically the Win32_NetworkAdapter and the Win32_NetworkAdapterConfiguration. I provided a fairly straightforward example of using the latter in thread222-1454008
 
Well, if I could find the second CD of my Visual Studio Dot Net, I would not be past using dot net.

Kevin
Tektility Inc
Maximizing Potential Through Technology
 
I'm not sure how .Net will help, the raft of dependencies is fantastically large by comparison.

The easy way without external components might be:

UserControl HTTPGet
Code:
Option Explicit

Public Event FetchComplete(ByVal Text As String)

Public Sub Fetch(ByVal URL As String)
    UserControl.AsyncRead URL, vbAsyncTypeByteArray, "Tag", vbAsyncReadForceUpdate
End Sub

Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
    RaiseEvent FetchComplete(StrConv(AsyncProp.Value, vbUnicode))
End Sub

Form Form1
Code:
Option Explicit

Private Sub Form_Load()
    HTTPGet1.Fetch "[URL unfurl="true"]http://www.whatismyip.com/automation/n09230945.asp"[/URL]
End Sub

Private Sub HTTPGet1_FetchComplete(ByVal Text As String)
    Label1.Caption = Text
End Sub


Of course in WinXP and later you also have Reg-Free COM as a solution for flash media (zero-installation) programs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top