private string GetClientIP()
{
string ipaddress = string.Empty;
if (Request.ServerVariables["remote_addr"] != null)//发出请求的远程主机的ip地址
{
ipaddress = Request.ServerVariables["remote_addr"];
}
else if (Request.ServerVariables["http_via"] != null)//判断是否设置代理,若使用了代理
{
if (Request.ServerVariables["http_x_forwarded_for"] != null)//获取代理服务器的ip
{
ipaddress = Request.ServerVariables["http_x_forwarded_for"];
}
else
{
ipaddress = Request.UserHostAddress;
}
}
else
{
ipaddress = Request.UserHostAddress;
}
return ipaddress;
}
获取远程客户端的真实IP地址
最新推荐文章于 2024-08-13 07:59:30 发布