How to get Client's Location using IPAddress

You can consume free Web Service, which can give IP Address Location Details.

http://www.aspsnippets.com/post/2009/04/12/Find-Visitors-Geographic-Location-using-IP-Address-in-ASPNet.aspx

The Following function returns Location Details as DataTable:

private DataTable GetLocation(string ipaddress)

{

//Create a WebRequest

WebRequest rssReq = WebRequest.Create("http://freegeoip.appspot.com/xml/" + ipaddress);

//Create a Proxy

WebProxy px = new WebProxy("http://freegeoip.appspot.com/xml/" + ipaddress, 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());

//Create a new DataSet

DataSet ds = new DataSet();

//Read the Response into the DataSet

ds.ReadXml(xtr);

return ds.Tables[0];

}

catch

{

return null;

}

}

Thank You.

Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

Update Excel Sheet using C#, Where Excel not Installed on Server