R
rofloller
Guest
VB6: Get your real IP-address
You need to enable Microsoft Internet Controls from Project -> Components... and add Inet control to your form and rename it to Inet instead of Inet1.
You need to enable Microsoft Internet Controls from Project -> Components... and add Inet control to your form and rename it to Inet instead of Inet1.
Code:
Private Sub Form_Load()
MsgBox RealIP
End Sub
Private Function RealIP()
On Error GoTo err
Dim before As String
Dim sitehtml As String
Dim myIP As String
Dim after As String
sitehtml = Inet.OpenURL("http://www.ip-adress.com/")
While Inet.StillExecuting
DoEvents
Wend
DivideText sitehtml, "My IP address: ", "</span></b></font></span>", before, myIP, after
RealIP = myIP
Exit Function
err:
RealIP = "ERROR: " & Error
End Function
Private Sub DivideText(ByVal txt As String, _
ByVal target1 As String, ByVal target2 As String, _
ByRef before As String, ByRef between As String, _
ByRef after As String)
Dim pos As Long
' Get the text before target1.
pos = InStr(txt, target1)
If pos = 0 Then
' target1 is missing. Set before = "".
before = ""
Else
' Set before.
before = Left$(txt, pos - 1)
' Remove up to target1 from the string.
txt = Mid$(txt, pos + Len(target1))
End If
' Get the text before target2.
pos = InStr(txt, target2)
If pos = 0 Then
' target2 is missing. Set between = "".
between = ""
Else
' Set between.
between = Left$(txt, pos - 1)
' Remove up to target2 from the string.
txt = Mid$(txt, pos + Len(target2))
End If
after = txt
End Sub

