Thursday, July 2, 2009

How to get Client's Location using IPAddress

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

The Following function returns Location Details as DataTable:

private DataTable GetLocation(string ipaddress)


//Create a WebRequest

WebRequest rssReq = WebRequest.Create("" + ipaddress);

//Create a Proxy

WebProxy px = new WebProxy("" + ipaddress, true);

//Assign the proxy to the WebRequest

rssReq.Proxy = px;

//Set the timeout in Seconds for the WebRequest

rssReq.Timeout = 2000;



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


return ds.Tables[0];




return null;



Thank You.

No comments: