Click here to Skip to main content
11,647,640 members (67,676 online)
Click here to Skip to main content
Add your own
alternative version

Retrieve information about your IP

, 10 Mar 2013 CPOL 16.3K 1.4K 17
Retrieve information about your IP from a website.
begi_iplocator-v2-noexe.zip
bEGI IPLocator
bEGI IPLocator
bin
Release
bEGI IPLocator.vshost.exe.manifest
iP.ico
My Project
Application.myapp
Settings.settings
bEGI IPLocator.suo
begi_iplocator-v2.zip
bEGI IPLocator.exe
bEGI IPLocator.vshost.exe
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
Settings.settings
bEGI IPLocator.suo
CSharp-IP_Informations-noexe.zip
IP Informations
IP Informations
IP Informations.csproj.user
IP.ico
Properties
Settings.settings
Resources
Background.bmp
IP Informations.suo
CSharp-IP_Informations.zip
bin
Release
IP Informations.exe
IP Informations.csproj.user
IP.ico
Settings.settings
Background.bmp
IP Informations.suo
IPLocator-noexe.zip
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
Settings.settings
Resources
Thumbs.db
untitled.JPG
bEGI IPLocator.suo
IPLocator.zip
bEGI IPLocator.exe
bEGI IPLocator.vshost.exe
bEGI IPLocator.vshost.exe.manifest
iP.ico
Application.myapp
Settings.settings
Thumbs.db
untitled.JPG
bEGI IPLocator.suo
PCinfo.zip
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...

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