隐藏

通过HTTP_USER_AGENT 分析访问者的操作系统环境

发布:2020/9/12 11:10:32作者:管理员 来源:本站 浏览次数:1084

HTTP_USER_AGENT是浏览器访问服务器的时候带过去的

public static string SystemCheck()

      {
          try
          {
              string userAgent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
              if (string.IsNullOrEmpty(userAgent))
              {
                  return "无法获取HTTP_USER_AGENT";
              }
 
              string version = "未知";
              if (userAgent.Contains("NT 5.0"))
              {
                  version = "Windows 2000";
              }
              else if (userAgent.Contains("Mac"))
              {
                  version = "Mac";
              }
              else if (userAgent.Contains("Unix"))
              {
                  version = "UNIX";
              }
              else if (userAgent.Contains("Linux"))
              {
                  version = "Linux";
              }
              else if (userAgent.Contains("SunOS"))
              {
                  version = "SunOS";
              }
              else if (userAgent.Contains("YandexBot"))
              {
                  version = "俄罗斯Yandex的爬虫程序";
              }
              else if (userAgent.Contains("Baiduspider-mobile"))
              {
                  version = "百度移动搜索爬虫程序";
              }
              else if (userAgent.Contains("Baiduspider-image"))
              {
                  version = "百度图片搜索爬虫程序";
              }
              else if (userAgent.Contains("Baiduspider-video"))
              {
                  version = "百度视频搜索爬虫程序";
              }
              else if (userAgent.Contains("Baiduspider-news"))
              {
                  version = "百度新闻搜索爬虫程序";
              }
              else if (userAgent.Contains("Baiduspider"))
              {
                  version = "百度爬虫程序";
              }
              else if (userAgent.Contains("bingbot"))
              {
                  version = "必应爬虫程序";
              }
              else if (userAgent.Contains("Googlebot"))
              {
                  version = "谷歌爬虫程序";
              }
              else if (userAgent.Contains("MSNBot"))
              {
                  version = "MSN爬虫程序";
              }
              else if (userAgent.Contains("YoudaoBot"))
              {
                  version = "有道爬虫程序";
              }
              else if (userAgent.Contains("Sogou"))
              {
                  version = "搜狗爬虫程序";
              }
              else if (userAgent.Contains("JikeSpider"))
              {
                  version = "即刻爬虫程序";
              }
              else if (userAgent.Contains("Sosospider"))
              {
                  version = "搜搜爬虫程序";
              }
              else if (userAgent.Contains("360Spider"))
              {
                  version = "360爬虫程序";
              }
              else if (userAgent.Contains("Yahoo"))
              {
                  version = "雅虎爬虫";
              }
              else if (userAgent.Contains("NT 5.1"))
              {
                  version = "Windows XP";
              }
              else if (userAgent.Contains("NT 5.2"))
              {
                  version = "Windows Server 2003";
              }
              else if (userAgent.Contains("NT 6.0"))
              {
                  version = "Windows Vista/Server 2008";
              }
              else if (userAgent.Contains("NT 6.1"))
              {
                  version = "Windows 7/Windows Server 2008 R2";
              }
              else if (userAgent.Contains("NT 6.2"))
              {
                  version = "Windows 8.0/Windows Server 2012/Windows Phone 8";
              }
              else if (userAgent.Contains("NT 6.3"))
              {
                  version = "Windows 8.1/Windows Server 2012 R2 ";
              }
              else if (userAgent.Contains("NT 6.4"))
              {
                  version = "Windows 10 NT6.4内核";
              }
              else if (userAgent.Contains("NT 10"))
              {
                  version = "Windows 10";
              }
              else if (userAgent.Contains("Me"))
              {
                  version = "Windows Me";
              }
              else if (userAgent.Contains("98"))
              {
                  version = "Windows 98";
              }
              else if (userAgent.Contains("95"))
              {
                  version = "Windows 95";
              }
              else if (userAgent.Contains("NT"))
              {
                  version = "Windows NT4.0以下";
              }
 
              return version;
          }
          catch (Exception ex)
          {
              return ex.Message;
          }
      }