如何检测安装在网页NET框架(纯HTML或PHP)(How to detect .NET frame

2019-09-27 15:59发布

我需要显示一个网页(PHP)如果满足下列条件之一满足的其他信息:

  • .NET框架安装在客户端机器上低于3.5
  • 无法确定是否.NET Framework 3.5的安装或者未在客户机上

我知道有些浏览器(如果不是唯一的一个,IE)派遣他的标签信息。

可以在任何的你我提供他的建议?

网站建于PHP。

谢谢!

编辑:

建议的答复是不完整和/或不给我提供一个强大的解决方案。

Answer 1:

这里是我实际上是我的一个朋友提出并意识到有这个线程,这样搞什么赏金另一个版本:)

这是完全正常的,但只有在User-Agent字符串作为有这样做的没有替代手段。

核心类:

class NETFrameworkChecker
{
    //General String / Array holders
    var $original_au,$ua_succesParse,$ua_componants,$ua_dotNetString,$CLRTag = "";

    //IsInstalled
    var $installed = false;

    //Version holders
    public $major = 0,$minor = 0,$build = 0;

    public function __construct($ua = false)
    {
        $this->original_au = $ua !== false ? $ua : $_SERVER['HTTP_USER_AGENT'];
        $this->ParserUserAgent();
    }

    public function Installed(){return (bool)$this->installed;}

    public function AUTag(){return $this->CLRTag;}

    //Version Getters
    public function getMajor(){return $this->major;}
    public function getMinor(){return $this->minor;}
    public function getBuild(){return $this->build;}

    private function ParserUserAgent()
    {
        $this->ua_succesParse = (bool) preg_match('/(?<browser>.+?)\s\((?<components>.*?)\)/',$this->original_au,$this->ua_componants);
        if($this->ua_succesParse)
        {
            $this->ua_componants = explode(';',$this->ua_componants['components']);
            foreach($this->ua_componants as $aComponant)
            {
                $aComponant = trim($aComponant);
                if(substr(strtoupper($aComponant),0,4) == ".NET")
                {
                    //We have .Net Installed
                    $this->installed = true;
                    $this->CLRTag = $aComponant;

                    //Lets make sure we can get the versions
                    $gotVersions = (bool)preg_match("/\.NET.CLR.+?(?<major>[0-9]{1})\.(?<minor>[0-9]{1})\.(?<build>[0-9]+)/si",$aComponant,$versions);
                    if($gotVersions)
                    {
                        $this->major = (int)$versions['major'];
                        $this->minor = (int)$versions['minor'];
                        $this->build = (int)$versions['build'];
                    }
                    break;
                }
            }
        }
    }
}

实例应用:

$Net = new NETFrameworkChecker(); //leave first param blank to detect current user agent

if($Net->Installed())
{
   if($Net->getMajor()> 2 && $Net->getMinor() >= 0)
   {
      //User is using a >NET system thats greater than 2.0.0000
      if($Net->GetBuild() >= 0200)
      {
         //We can do stuff with so that's only supported from this build up-words
      }
   }else
   {
      //Redirect them asking them to upgrade :) pretty please
   }
}

如果你还需要检查的自定义UA字符串从DB可以说,

$Net = new NETFrameworkChecker("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Pivim Multibar; GTB6.4; .NET CLR 2.0.50727)");


Answer 2:

得到这个信息的唯一途径是从user agent的浏览器发送。 你可以从那里解析.NET版本。 但是请注意,客户端可以伪造这些信息或完全忽略它,所以我不会在此基础上的任何关键功能。



Answer 3:

我会尝试做在PHP中的UserAgent,例下面一个的strstr

一个.NET用户代理: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Pivim Multibar; GTB6.4; .NET CLR 2.0.50727)

PHP的:

<?php
function DotNetInstalled($ua = false)
{
    $ua = $ua ? $ua : $_SERVER['HTTP_USER_AGENT'];
    //return (strstr('.NET CLR',$ua) !== false);
    $matches = preg_match('^\.NET CLR ([0-4]+\.)?([0-9]\.)?(\*|\d+)$',$ua);
    if((int)$matches[1] > 0)
    {
       return array(
           (int)$matches[1],
           (int)$matches[2],
           (int)$matches[3],
       );
    }
    return false;
}

if(false !== ($version = DotNetInstalled()))
{
   //Show me the money
   //$version[0] = 2
   //$version[1] = 0
   //$version[2] = 50727
}
?>

我也想看看下面的PEAR包: http://pear.php.net/package/Net_UserAgent_Detect ?>



Answer 4:

有关在UserAgent的.NET CLR版本信息:

  • http://www.hanselman.com/blog/TheNETFrameworkAndTheBrowsersUserAgentString.aspx
  • http://msdn.microsoft.com/en-us/library/ms537503.aspx


文章来源: How to detect .NET framework installed in a web page (pure HTML or PHP)