string IpAddress3 = Request.UserHostAddress.ToString();
Response.Write(IpAddress3);
string IpAddress2 = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; //从代理IP获取真实IP
//如果未使用代理或未取到则为null(并不是所有的代理都可以取到)
try
{
Response.Write(IpAddress2.ToString());
}
catch(NullReferenceException NE)
{
string IpAddress = Request.ServerVariables["REMOTE_ADDR"] ;
Response.Write(IpAddress.ToString());
}这样并不能取得真正的IP