c#中获取服务器IP,客户端IP以及其它

客户端ip:
1Request.ServerVariables.Get("Remote_Addr").ToString(); 
客户端主机名:
1Request.ServerVariables.Get("Remote_Host").ToString(); 
客户端浏览器IE:
Request.Browser.Browser; 
客户端浏览器 版本号:
Request.Browser.MajorVersion;//
客户端操作系统:
Request.Browser.Platform; 
服务器ip:
Request.ServerVariables.Get("Local_Addr").ToString(); 
服务器名:
Request.ServerVariables.Get("Server_Name").ToString();
如果你想进一步了解ServerVariables,可以用
1foreach(String o in Request.ServerVariables)
2Response.Write(o+"="+Request.ServerVariables[o]+"<br>"); 
3}
 
4
获取客户端IP方法
 1public string GetIP()
 2    {
 3        string uip = "";
 4        if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"!= null)
 5        {
 6            uip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
 7        }

 8        else
 9        {
10            uip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
11        }

12        return uip;
13    }
posted @ 2008-02-14 17:02  龍峸.大卫  阅读(1412)  评论(2编辑  收藏  举报