Get Visitors Ip address and Get Country details by ipaddress

Posted by Gopal_nivas under ASP.NET on 7/14/2011 | Points: 10 | Views : 22740 | Status : [Member] | Replies : 4
hi..

i want to get visitors location based ip address and based on the ip address i want to get the country details in asp.net c#.

i was used the below coding


public string IpAddress()
{
string strIpAddress;
strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIpAddress == null)
{
strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
return strIpAddress;
}
private DataTable GetGeoLocation(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;
}
}


but it displays the ip address as 127.0.0.0 and location as null.

so how to solve this issue.

need ur suggestions with examples

regards
gopal.s




Responses

Posted by: Lakn2 on: 7/14/2011 [Member] Starter | Points: 25

Up
0
Down
Refer this
http://www.dotnetlogix.com/KB/Article/33/How-to-get-visitors-Country,-longitude,-latitude-from-IP-address-is-asp.net

Thanks&Regards
LakshmiNarayana Nalluri.

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 7/14/2011 [Member] [MVP] Bronze | Points: 25
Posted by: Jpchoudhari on: 7/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

http://www.ip2location.com/faqs-ip-country.aspx

Kind Regards,
Jaydeep Choudhari

Kind Regards,
Jay

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Aarlene on: 4/7/2012 [Member] Starter | Points: 25

Up
0
Down
yeah its good to know visitors Ip address and get country details for security logging or perhaps tracing . Using free web services is the easy way to get the location of the user based on its IP address.I got it from http://ip-details.com/ip-details-client/ for my website!


Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response