我想获取我的网站访问者的地理位置并将其存储在我的数据库中,已经获取了 IP 地址。
我正在使用 asp.net 3.0
protected void Page_Load( object sender, EventArgs e)
{
// Track Visitors
string ipAddress = IpAddress();
string hostName = Dns .GetHostByAddres(ipAddress).HostName;
StreamWriter wrtr = new StreamWriter (Server.MapPath( "visitors.log" ), true );
wrtr.WriteLine( DateTime .Now.ToString() + " | " + ipAddress + " | " + hostName + " | " + Request.Url.ToString());
wrtr.Close();
}
private string IpAddress()
{
string strIpAddress;
strIpAddress = Request.ServerVariables[ "HTTP_X_FORWARDED_FOR" ];
if (strIpAddress == null )
strIpAddress = Request.ServerVariables[ "REMOTE_ADDR" ];
return strIpAddress;
}