Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork BackgroundWorker1.WorkerSupportsCancellation = True Try Dim ur As New Uri("http://www.find-ip-address.org/") Dim req As HttpWebRequest = HttpWebRequest.Create(ur) Dim res As HttpWebResponse = req.GetResponse() If (res.StatusCode = HttpStatusCode.OK) Then Dim receiveStream As Stream = res.GetResponseStream() Dim readStream As StreamReader = Nothing If (res.CharacterSet = Nothing) Then readStream = New StreamReader(receiveStream) Else readStream = New StreamReader(receiveStream, Encoding.GetEncoding(res.CharacterSet)) Dim data As String = readStream.ReadToEnd() res.Close() readStream.Close() Dim left = "My IP Country Name:" Dim right = "IP Address Lookup Location" Dim indexLeft As Integer = data.IndexOf(left) Dim indexRight As Integer = data.IndexOf(right) lookupData = data.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length) flagLocation = extractSubject("</font> <img src='", "'><br>My IP Country Continent<") End If End If Catch End Try End Sub Private Function extractSubject(ByVal left As String, ByVal right As String) Try Dim indexLeft As Integer = lookupData.IndexOf(left) Dim indexRight As Integer = lookupData.IndexOf(right) Return lookupData.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length) Catch Return "Not Resolved!" End Try End Function #Region "informations" Private Function publicIP() As String Return extractSubject(">My IP Address lookup for ", " show IP which") End Function #End Region Public Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted tbPublicIP.Text = publicIP() BackgroundWorker1.CancelAsync() End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)