Click here to Skip to main content
13,249,813 members (85,028 online)
Click here to Skip to main content
Add your own
alternative version

Stats

22.7K views
1.8K downloads
17 bookmarked
Posted 3 Oct 2012

Retrieve information about my IP

, 3 Oct 2012
Rate this:
Please Sign up or sign in to vote.
Retrieve information about my IP from a website.
This is an old version of the currently published tip/trick.

Introduction

We create a connection to the website "FIND-IP-ADDRESS.ORG" which automatically obtains our IP when we create a connection to it. With our IP it obtains info about us and stores them in its website. Now we want to retrieve these information and download it into our application.

We download the source code (HTML) of the page and we trim and split them. At the end it should remain only the infos we need.

There are two functions, one button, some (8) labels, and textboxes.

Using the code

Imports System.IO
Imports System.Net
Imports System.Text

Public Class Form1
    Dim ur As New Uri("http://www.find-ip-address.org/")
    Dim htmlData As String
   
    Function downloadHTMLData() As Boolean
        Try
            Dim request As HttpWebRequest = HttpWebRequest.Create(ur)
            Dim response As HttpWebResponse = request.GetResponse()
            If (response.StatusCode = HttpStatusCode.OK) Then
                Dim receiveStream As Stream = response.GetResponseStream()
                Dim readStream As StreamReader = Nothing
                If (response.CharacterSet = Nothing) Then
                    readStream = New StreamReader(receiveStream)
                Else
                    readStream = New StreamReader(receiveStream, _
                                        Encoding.GetEncoding(response.CharacterSet))
                    Dim data As String = readStream.ReadToEnd()
                    response.Close()
                    readStream.Close()

                    ' WE SHORT THE HTML CODE, WE KEEP ONLY THE MAIN INFORMATIONS WE NEED FROM!
                    Dim s, e As String
                    s = "My IP Country Name:"
                    e = "IP Address Lookup Location"
                    Dim index1 As Integer = data.IndexOf(s)
                    Dim index2 As Integer = data.IndexOf(e)
                    Dim output As String = data.Substring(index1 + s.Length, index2 - index1 - s.Length)
                    htmlData = output
                End If
            End If
            Return True
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            Return False
        End Try
    End Function

    Private Function trimmHTMLText(ByVal startFrom As String, ByVal endAt As String)
        Dim index1 As Integer = htmlData.IndexOf(startFrom)
        Dim index2 As Integer = htmlData.IndexOf(endAt)
        Dim output As String = htmlData.Substring(index1 + startFrom.Length, index2 - index1 - startFrom.Length)
        Return output
    End Function

    Private Sub btLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLookup.Click
        btLookup.Enabled = False

        If downloadHTMLData() = True Then
            TextBox1.Text = trimmHTMLText(">My IP Address lookup</strong> for <b>", _
                            "</b> show IP which") ' MY IP ADDRESS
            TextBox2.Text = trimmHTMLText("City</b>:&nbsp;&nbsp; <font color='#980000'>", _
                            "</font><br><b>My IP Address Latitude</b>") ' IP ADDRESS CITY
            Dim txtbx3 As String = trimmHTMLText(")<br><br><strong>My IP Address Region" & _ 
                "</strong>: <font color='#980000'>", "</font><br><b>") ' MY ADDRESS REGION
            Dim s As String() = txtbx3.Split("<") : TextBox3.Text = s(0)
            TextBox4.Text = trimmHTMLText("Provider)</strong>:&nbsp;<font color='#980000'> ", _
                                          "</font><br /") ' MY ISP PROVIDER
            TextBox5.Text = trimmHTMLText(":&nbsp;&nbsp;<font color='#980000'> ", _
                                          "</font>&nbsp;&nbsp;<img src='") 'COUNTRY NAME
            TextBox6.Text = trimmHTMLText("My IP Address Latitude</b>: ", _
                            "<br><b>My IP Address Longtitude") ' MY IP ADDRESS LATITUDE
            TextBox7.Text = trimmHTMLText("My IP Address Longtitude</b>: ", _
                            "<br><br><strong>My ISP") ' MY IP ADDRESS LONGTITUDE
            TextBox8.Text = trimmHTMLText("My Time zone</b>: ", _
                            "<br><b>My Local time") ' MY TIME ZONE
            'GET COUNTRY FLAG
            PictureBox1.Load(ur.ToString + trimmHTMLText("</font>&nbsp;&nbsp;<img src='", _
                             "'><br><strong>My IP Country Continent<"))
        End If
        btLookup.Enabled = True
    End Sub
End Class

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
 
Answer[My vote of 1] عمر الجبلي Pin
abogala13-Mar-13 18:41
memberabogala13-Mar-13 18:41 
GeneralRe: [My vote of 1] عمر الجبلي Pin
bEGI2314-Mar-13 2:39
memberbEGI2314-Mar-13 2:39 
GeneralRetrieve IP info Pin
Rick Sparks13-Mar-13 2:36
memberRick Sparks13-Mar-13 2:36 
GeneralRe: Retrieve IP info Pin
bEGI2313-Mar-13 6:07
memberbEGI2313-Mar-13 6:07 
GeneralRe: Retrieve IP info Pin
Rick Sparks13-Mar-13 11:10
memberRick Sparks13-Mar-13 11:10 
GeneralMy vote of 5 Pin
VitorHugoGarcia11-Mar-13 8:14
memberVitorHugoGarcia11-Mar-13 8:14 
SuggestionMake data search easier by searching for "<" after data Pin
Member 80729961-Mar-13 4:32
memberMember 80729961-Mar-13 4:32 
GeneralRe: Make data search easier by searching for "<" after data Pin
bEGI238-Mar-13 3:33
memberbEGI238-Mar-13 3:33 
GeneralRe: Make data search easier by searching for "<" after data Pin
Member 80729968-Mar-13 19:51
memberMember 80729968-Mar-13 19:51 
GeneralMy vote of 1 Pin
Mukund Thakker24-Dec-12 0:12
memberMukund Thakker24-Dec-12 0:12 
GeneralMy vote of 5 Pin
BertrandLQ17-Dec-12 3:26
memberBertrandLQ17-Dec-12 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 3 Oct 2012
Article Copyright 2012 by bEGI23
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid