Private Sub Command1_Click()
On Error GoTo Command1_Click_Error
Dim a As Integer, b As Integer
Dim strURL As String
Dim strIP As String
Dim strSearchPrefix As String
Dim strSearchSuffix As String
strSearchPrefix = "<TITLE>Your IP Is "
strSearchSuffix = " WhatIsMyIP.com</"
'we open the [url]www.whatismyip.com[/url] URL and read it whole into strURL, this can take some time
strURL = Inet1.OpenURL("http://www.whatismyip.com/")
'we find where the part before the IP is written
TryAgain:
a = InStr(1, strURL, strSearchPrefix)
'we find the part after the IP
b = InStr(a, strURL, strSearchSuffix)
' NOTE: the strURL doesnt have the actual Text you see in the browser in it, it has the HTML
'code of the site in it! You need to watch out for that
'And the IP itself is between these two!
''strIP = Mid(strURL, a + 18, b - (a + 18))
strIP = Trim(Mid(strURL, a + Len(strSearchPrefix), (b - a) - Len(strSearchSuffix) - 1))
'We let the user know what his IP is in form of message box
Text3.Text = strIP
'if user clicked Yes and he wants to copy the IP into the clipboard
'If temp = 6 Then
''first clear the clipboard
'Clipboard.Clear
''then assign new clipboard text - (our IP)
'Clipboard.SetText strIP
'End If
Text2.Text = Winsock1.LocalIP
Text1.Text = Winsock1.LocalHostName
On Error GoTo 0
Exit Sub
Command1_Click_Error:
If Err.Number = 5 Then
strSearchPrefix = "<TITLE>Your IP - "
GoTo TryAgain
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form Form1"
End If
End Sub