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地址
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.