首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

为啥获得的IP不是一段

2013-12-11 
为什么获得的IP不是一段为什么获取客户端IP,实际有时候得到好几段呢如58.219.133.170, 127.0.0.1, 10.210.

为什么获得的IP不是一段
为什么获取客户端IP,实际有时候得到好几段呢
如58.219.133.170, 127.0.0.1, 10.210.42.57
求解,求更好的代码,我的代码如下:

public static string KeHuDuanIP()
    {
        string e= HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (string.IsNullOrEmpty(e))
        {
            e= HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
        if (string.IsNullOrEmpty(e))
        {
            e= HttpContext.Current.Request.UserHostAddress;
        }
        return e;
    }
客户端IP
[解决办法]
因为经过多次代理,代理服务器将它们都附加到了x forward for上。

热点排行