Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.67/5 (5 votes)
See more:
how can i get information of city, state and country of any ip address

input is ip address...

and output should be city ,state and country of that ip address

please help me....

its urgent
Posted
Updated 26-Jan-12 20:58pm
v3
Comments
fjdiewornncalwe 26-Jan-12 9:52am    
That your issue is urgent, is of no concern to us.
That you repost your question is not acceptable on this site. If you have something to add or change in your question, then edit the original one. Please do not add another one like you did in this case.
Original Question
PKriyshnA 26-Jan-12 10:05am    
k sorry

Use HostIp.Info[^] and get the Geo API.
Or use any of the webservices available.


This[^] may help.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 26-Jan-12 9:53am    
A very good answer. +5.
NeptuneHACK! 26-Jan-12 13:15pm    
my 5
i use XmlTextReader to solve this problem....

for reference click on
http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx[^]

using XmlTextReader i solved my problem.......u can also.. :)

thnx

Have A Great Day
 
Share this answer
 
Comments
Richard MacCutchan 29-Jan-12 4:01am    
How can that find the city connected to an IP address?
code file for that solution is below,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
    DataClassesDataContext obj = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {   
        string ipaddress;
        ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (ipaddress == "" || ipaddress == null)
           ipaddress = Request.ServerVariables["REMOTE_ADDR"];

        // If you run this project on your local host (your computer) then you need to uncomment the next line to avoid getting the UNKOWN IP address.
        // Otherwise, the next line should be commented out if you are running this project on a web server.
        ipaddress = "27.121.103.12";//india
        //ipaddress = "27.50.103.12";//japan
        //ipaddress = "202.138.79.255";//australia
        //ipaddress = "27.116.59.255";//afdhanistan
        //ipaddress = "46.19.231.255";//albania
        
            

        // Lookup geographic location using IP address
        XmlTextReader XmlRdr = GetLocation(ipaddress);

        if (XmlRdr != null)
        {
            while (XmlRdr.Read())
            {
                if (XmlRdr.Name.ToString() == "cityName")
                {
                    lblCity.Text = XmlRdr.ReadString().Trim();
                }
                if (XmlRdr.Name.ToString() == "regionName")
                {
                    lblRegion.Text = XmlRdr.ReadString().Trim();
                }
                if (XmlRdr.Name.ToString() == "countryName")
                {
                    lblCountry.Text = XmlRdr.ReadString().Trim();
                }
                if (XmlRdr.Name.ToString() == "countryCode")
                {
                    lblCountryCode.Text = XmlRdr.ReadString().Trim(); 
                }
                //if (XmlRdr.Name.ToString() == "zipCode")
                //{
                //    lblZip.Text = XmlRdr.ReadString().Trim();
                //}
                if (XmlRdr.Name.ToString() == "longitude")
                {
                    lblLong.Text = XmlRdr.ReadString().Trim();
                }
                if (XmlRdr.Name.ToString() == "latitude")
                {
                    lblLat.Text = XmlRdr.ReadString().Trim();
                }
                if (XmlRdr.Name.ToString() == "timeZone")
                {
                    lblTime.Text = XmlRdr.ReadString().Trim();
                }   
                lblIP.Text = ipaddress;
            }
            XmlRdr.Close();
        }
        else
        {
            lblIP.Text = "IP not Detected";
        }
    }

    private XmlTextReader GetLocation(string ipaddress)
    {
        // Register at ipinfodb.com for a free key and put it here
        string myKey = "Your Api key Here";

        //Create a WebRequest
        WebRequest rssReq = WebRequest.Create("http://api.ipinfodb.com/v3/ip-city/?key=" + myKey + "&ip=" + ipaddress + "&format=xml");

        //Create a Proxy
        WebProxy px = new WebProxy("http://api.ipinfodb.com/v3/ip-city/?key=" + myKey + "&ip=" + ipaddress + "&format=xml", true);

        //Assign the proxy to the WebRequest
        rssReq.Proxy = px;

        //Set the timeout in Seconds for the WebRequest
        rssReq.Timeout = 2000;
        try
        {
            //Get the WebResponse 
            WebResponse rep = rssReq.GetResponse();

            //Read the Response in a XMLTextReader
            XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
            return xtr;

        }
        catch
        {
            return null;
        }
    }
    
}


thats great solution.....

Thnx & Regards,
PKriyshnA="PriyA+KrishnA"; :)
 
Share this answer
 
Comments
Member 9129971 15-May-14 4:08am    
what is this DataClassesDataContext obj = new DataClassesDataContext(); ??
I will help you to fix your problem. Visit the site Ip-Details.com ,here you will get country, state, city as output by giving his/her IP address as input. Here they are providing HTML code for that process. You can also embedded this in your website.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900