1. using System;   
  2. using System.Data;   
  3. using System.Configuration;   
  4. using System.Collections;   
  5. using System.Web;   
  6. using System.Web.Security;   
  7. using System.Web.UI;   
  8. using System.Web.UI.WebControls;   
  9. using System.Web.UI.WebControls.WebParts;   
  10. using System.Web.UI.HtmlControls;   
  11. using System.Data.SqlClient;   
  12. public partial class WebStart : System.Web.UI.UserControl   
  13. {   
  14.     protected void Page_Load(object sender, EventArgs e)   
  15.     {   
  16.   
  17.     }   
  18.     //获取浏览器版本号   
  19.     public string getBrowser() {   
  20.         string browsers;   
  21.         HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;   
  22.         string aa = bc.Browser.ToString();   
  23.         string bb = bc.Version.ToString();   
  24.         browsers = aa + bb;   
  25.         return browsers;   
  26.     }   
  27.     //获取客户端IP地址   
  28.     public string getIP()   
  29.     {   
  30.         string result = String.Empty;   
  31.         result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];   
  32.         if (null == result || result == String.Empty)   
  33.         {   
  34.             result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];   
  35.         }   
  36.         if (null == result || result == String.Empty)   
  37.         {   
  38.             result = HttpContext.Current.Request.UserHostAddress;   
  39.         }   
  40.         if (null == result || result == String.Empty)   
  41.         {   
  42.             return "0.0.0.0";   
  43.         }   
  44.         return result;   
  45.     }   
  46.     //获取操作系统版本号   
  47.     public static string SystemCheck()   
  48.     {   
  49.         string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];   
  50.   
  51.         if (Agent.IndexOf("NT 4.0") > 0)   
  52.         {   
  53.             return "Windows NT ";   
  54.         }   
  55.         else if (Agent.IndexOf("NT 5.0") > 0)   
  56.         {   
  57.             return "Windows 2000";   
  58.         }   
  59.         else if (Agent.IndexOf("NT 5.1") > 0)   
  60.         {   
  61.             return "Windows XP";   
  62.         }   
  63.         else if (Agent.IndexOf("NT 5.2") > 0)   
  64.         {   
  65.             return "Windows 2003";   
  66.         }   
  67.         else if (Agent.IndexOf("NT 6.0") > 0)   
  68.         {   
  69.             return "Windows Vista";   
  70.         }   
  71.         else if (Agent.IndexOf("WindowsCE") > 0)   
  72.         {   
  73.             return "Windows CE";   
  74.         }   
  75.         else if (Agent.IndexOf("NT") > 0)   
  76.         {   
  77.             return "Windows NT ";   
  78.         }   
  79.         else if (Agent.IndexOf("9x") > 0)   
  80.         {   
  81.             return "Windows ME";   
  82.         }   
  83.         else if (Agent.IndexOf("98") > 0)   
  84.         {   
  85.             return "Windows 98";   
  86.         }   
  87.         else if (Agent.IndexOf("95") > 0)   
  88.         {   
  89.             return "Windows 95";   
  90.         }   
  91.         else if (Agent.IndexOf("Win32") > 0)   
  92.         {   
  93.             return "Win32";   
  94.         }   
  95.         else if (Agent.IndexOf("Linux") > 0)   
  96.         {   
  97.             return "Linux";   
  98.         }   
  99.         else if (Agent.IndexOf("SunOS") > 0)   
  100.         {   
  101.             return "SunOS";   
  102.         }   
  103.         else if (Agent.IndexOf("Mac") > 0)   
  104.         {   
  105.             return "Mac";   
  106.         }   
  107.         else if (Agent.IndexOf("Linux") > 0)   
  108.         {   
  109.             return "Linux";   
  110.         }   
  111.         else if (Agent.IndexOf("Windows") > 0)   
  112.         {   
  113.             return "Windows";   
  114.         }   
  115.         return "未知类型";   
  116.   
  117.     }   
  118.     
  119.   
  120. }  

.NET 开发讨论组 QQ技术群24739911,欢迎加入