下面的这些代码,能够绕过代理,获取访客真实的IP地址。代码如下:
string MyIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == MyIP || MyIP == String.Empty)
{
MyIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == MyIP || MyIP == String.Empty)
{
MyIP = HttpContext.Current.Request.UserHostAddress;
}
如果是本地,获取的IP为:127.0.0.1
如果是互联网用户,获取的IP地址为:222.172.200.68等形式。