Click here to Skip to main content
13,197,548 members (48,816 online)
Click here to Skip to main content

Stats

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

Retrieve information about your IP

, 10 Mar 2013
Retrieve information about your IP from a website.
bEGI IPLocator
bEGI IPLocator
bin
Release
bEGI IPLocator.vshost.exe.manifest
iP.ico
My Project
Application.myapp
bEGI IPLocator.suo
bEGI IPLocator.exe
bEGI IPLocator.vshost.exe
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
bEGI IPLocator.suo
IP Informations
IP Informations
IP Informations.csproj.user
IP.ico
Properties
Resources
Background.bmp
IP Informations.suo
bin
Release
IP Informations.exe
IP Informations.csproj.user
IP.ico
Background.bmp
IP Informations.suo
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
Resources
Thumbs.db
untitled.JPG
bEGI IPLocator.suo
bEGI IPLocator.exe
bEGI IPLocator.vshost.exe
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
Thumbs.db
untitled.JPG
bEGI IPLocator.suo
PCinfo.exe
/// ****************************************
/// * 		    Created by bEGI	           *
/// *  http://www.youtube.com/user/MCneun  *
/// *	       VB & C# Programmer	       *
/// ****************************************



using System;
using System.IO;
using System.Net;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;


namespace IP_Informations
{
    public partial class IPInfo : Form
    {
        string lookupData;

        public IPInfo()
        {
            InitializeComponent();
        }

        private void btLookup_Click(object sender, EventArgs e)
        {
            getIPInfos();
        }

        private void getIPInfos()
        {
            btLookup.Enabled = false;
            try
            {
                Uri ur = new Uri("http://www.find-ip-address.org/");
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(ur);
                System.Net.HttpWebResponse res = (System.Net.HttpWebResponse) req.GetResponse();
                if (res.StatusCode == HttpStatusCode.OK)
                {
                    Stream receiveStream = res.GetResponseStream();
                    StreamReader readStream = null;
                    if (res.CharacterSet == null)
                    {
                        readStream = new StreamReader(receiveStream);
                    }
                    else
                    {
                        readStream = new StreamReader(receiveStream, Encoding.GetEncoding(res.CharacterSet));
                        string data = readStream.ReadToEnd();
                        res.Close();
                        readStream.Close();
                        string left = "My IP Country Name:";
                        string right = "IP Address Lookup Location";
                        int indexLeft = data.IndexOf(left);
                        int indexRight = data.IndexOf(right);
                        lookupData = data.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length);
                    }
                }

                labelCountry.Text = extractSubject(":&nbsp;&nbsp;<font color='#980000'> ", "</font>&nbsp;&nbsp;<img src='"); //COUNTRY NAME
                string myStr = extractSubject("</font>&nbsp;&nbsp;<img src='", "'><br><strong>My IP Country Continent<");
                string[] countryCode = myStr.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                labelCountry.Text += "(" + countryCode[2].Remove(2).ToUpper() + ")";
                textBoxExternal.Text = extractSubject(">My IP Address lookup</strong> for <b>", "</b> show IP which"); // MY IP ADDRESS
                textBoxInternal.Text = getInternalIP();
                textBoxCity.Text = extractSubject("City</b>:&nbsp;&nbsp; <font color='#980000'>", "</font><br><b>My IP Address Latitude</b>"); // IP ADDRESS CITY
                string tbRegion = extractSubject(")<br><br><strong>My IP Address Region</strong>: <font color='#980000'>", "</font><br><b>"); // MY ADDRESS REGION
                string[] str = tbRegion.Split('<');
                textBoxRegion.Text = str[0];
                textBoxISP.Text = extractSubject("Provider)</strong>:&nbsp;<font color='#980000'> ", "</font><br /"); // MY ISP PROVIDER
                textBoxTimeZone.Text = extractSubject("My Time zone</b>: ", "<br><b>My Local time"); // MY TIME ZONE
                textBoxLat.Text = extractSubject("My IP Address Latitude</b>: ", "<br><b>My IP Address Longtitude"); // MY IP ADDRESS LATITUDE
                textBoxLng.Text = extractSubject("My IP Address Longtitude</b>: ", "<br><br><strong>My ISP"); // MY IP ADDRESS LONGTITUDE

                pictureBoxFlag.Load("http://www.find-ip-address.org/" + extractSubject("</font>&nbsp;&nbsp;<img src='", "'><br><strong>My IP Country Continent<")); // COUNTRY FLAG
            }
            catch
            {
            }
            btLookup.Enabled = true;
        }

        private string extractSubject(string left, string right)
        {
            try
            {
                int indexLeft = lookupData.IndexOf(left);
                int indexRight = lookupData.IndexOf(right);
                return lookupData.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length);
            }
            catch
            {
                return "Unable to retrieve!";
            }
        }

        private string getInternalIP()
        {
            try
            {
                IPHostEntry iphostentry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName());
                return ((System.Net.IPAddress)iphostentry.AddressList.GetValue(0)).ToString();
            }
            catch
            {
                return "Unable to retrieve!";
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171020.1 | Last Updated 11 Mar 2013
Article Copyright 2012 by bEGI23
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid