This isn't really a good method since it needs to be changed router to
router.
Here are two slightly better alternatives:
You could hit an external website like
http://www.whatismyip.com/ which will
return the user's public IP address. The only problem with this method is
that the site may go down or be otherwise unaccessable. Note you can create
your own website that will simply return the IP without the need for parsing
and it might be more reliable; however, it can still go down.
The other alternative which works very well if your router supports it, is
to use a dynamic dns service like dyndns.org. If your router supports this
function you can sign up for a free account and have an address like
<hostname>.dyndns.org. The router will then automatically refresh the IP
every so often. Resolving this dns entry will be the IP of the router.
Allowing the user to simply input the dns address to resolve will pretty
much cover every case so the user could use any service they desired..
If anyone can think of any other more generic solutions please post them,
but for now these are the best methods I can come up with.
"Brooke" <Br****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
Steve, I am not sure what router you have, but here is how I did it. If
you hear of a better way, please let me know.
Oh, You will need to make a new form and add these properties
webbrowser - called WebBrowser1
label - called label1
timer - Timer1
---------------------------------------------------------
Option Explicit
Dim webtx As String
Private Function RefreshPage()
Dim K1 As Integer, k2 As Integer, k3 As Integer, result As Integer
Dim IPaddress1 As String, IPaddress2 As String
If WebBrowser1.Visible = True Then
WebBrowser1.Refresh
End If
webtx = WebBrowser1.Document.body.innertext
If Len(webtx) > 50 Then
K1 = InStr(1, webtx, "IP Address")
k2 = InStr(K1 + 11, webtx, "IP Address")
IPaddress1 = Mid(webtx, k2 + 11, 16)
k3 = InStr(IPaddress1, " ")
IPaddress2 = Mid(IPaddress1, 1, k3 - 1)
Else
result = MsgBox("Login Not Confirmed, Please Try Again",
vbOKCancel) If result = 1 Then
WebBrowser1.Stop
Form_Load
Else
End
End If
End If
WebBrowser1.Visible = False
Label1.Caption = "IP = " + IPaddress2
End Function
Private Sub Form_Load()
Dim result As Boolean
' position the Web Browser control below the command button.
WebBrowser1.Move 0, 200
' navigate to a Web site for testing purposes.
WebBrowser1.Navigate "192.168.0.1/st_devic.html"
Do Until Not WebBrowser1.Busy And WebBrowser1.ReadyState = 4
DoEvents
Loop
result = RefreshPage()
End Sub
' Use this if you want to keep the program running and refresh the IP once
and hour
Private Sub Timer1_Timer()
Dim result As Boolean, testtime As Integer
testtime = Minute(Time)
If testtime = 0 Then
result = RefreshPage()
End If
If testtime = 25 Then
result = RefreshPage()
End If
End Sub