Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the location of the visitor visiting my website.I am able to get his/her Ip address.
Please suggest me solution other than using API.
Posted
Comments
Sinisa Hajnal 3-Dec-14 9:07am    
Why wouldn't you use APIs made for that?
Syed.net 3-Dec-14 9:10am    
Because i tried a lot of them but only faced errors.If you have any particular which is functional please suggest, can't it be done without using ApI's?

1 solution

 
Share this answer
 
Comments
Syed.net 3-Dec-14 9:12am    
Already tried the above link,its not working.
Praveen Kumar Upadhyay 3-Dec-14 9:23am    
http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?ipAddress=

This is returning proper result.
Syed.net 3-Dec-14 9:39am    
public void GetIP()
{
string Str = "";
Str = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(Str);
IPAddress[] addr = ipEntry.AddressList;
//return addr[addr.Length - 2].ToString();
GetLocation(addr[addr.Length - 2].ToString());


}
public DataTable GetLocation(string strIPAddress)
{
//Create a WebRequest with the current Ip
WebRequest _objWebRequest =
WebRequest.Create("http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?ipAddress="
+ strIPAddress);
//Create a Web Proxy
WebProxy _objWebProxy =
new WebProxy("http://ws.cdyne.com/ip2geo/ip2geo.asmx/"
+ strIPAddress, true);

//Assign the proxy to the WebRequest
_objWebRequest.Proxy = _objWebProxy;

//Set the timeout in Seconds for the WebRequest
_objWebRequest.Timeout = 2000;

try
{
//Get the WebResponse
WebResponse _objWebResponse = _objWebRequest.GetResponse();//The remote server returned an error: (500) Internal Server Error.
//Read the Response in a XMLTextReader
XmlTextReader _objXmlTextReader
= new XmlTextReader(_objWebResponse.GetResponseStream());

//Create a new DataSet
DataSet _objDataSet = new DataSet();
//Read the Response into the DataSet
_objDataSet.ReadXml(_objXmlTextReader);

return _objDataSet.Tables[0];
}
catch
{
return null;
}
}
Syed.net 3-Dec-14 9:40am    
i have marked the place where i am getting error.
//The remote server returned an error: (500) Internal Server Error.
Praveen Kumar Upadhyay 3-Dec-14 12:22pm    
The problem is with your HTTP Request

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