1检测用户当前浏览器是否将域名的ip添加信任站点

js代码

//域名ip的获取

var hostname = window.location.hostname;
 
    var WshShell = new ActiveXObject("WScript.Shell");
    //IP的正则表达式
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;
    //根据域名判断是否存在可信站点
   
    if(hostname != "localhost" && !reg.test(hostname)){
 /*
      var domainSFlag = false,domainEFlag = false,domainSEFlag = false,domainSSEFlag = true;
      var hostnamePrefix = "",hostnameSuffix = "";
      var indexOf = hostname.indexOf(".");
      if(indexOf != -1){
        hostnamePrefix = hostname.substring(0, indexOf);
        hostnameSuffix = hostname.substring(indexOf+1, hostname.length);
        try{
          WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\" + hostname + "\\http");   
        }catch(e){
          domainEFlag = true;
        }
        if(domainEFlag){
          try{
            WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\" + hostnameSuffix + "\\" + hostnamePrefix + "\\http");   
          }catch(e){
            domainSFlag = true;
          }
        }
        //判断其合法性
        if(domainEFlag && domainSFlag){
          try{
            WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\" + hostnameSuffix + "\\" + hostnamePrefix + "\\*");   
            var tipInfo = "<div>您加入的可信站点不是合法的可信站点,请以<span style='color:red;'>http://</span>开头!</div>";
            alert(tipInfo);
            return;
          }catch(e){}
        }
      }else{
        try{
          WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\" + hostname + "\\http");   
        }catch(e){
          domainSEFlag = true;
        }
        //判断其合法性
        if(domainSEFlag){
          try{
            WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\" + hostname + "\\*");   
            var tipInfo = "<div>您加入的可信站点不是合法的可信站点,请以<span style='color:red;'>http://</span>开头!</div>";
            alert(tipInfo);
            return;
          }catch(e){}
        }
      }
      if((domainSFlag && domainEFlag) || domainSEFlag){
        var tipInfo = "域名为" + hostname + "的可信任站点不存在!";
        alert(tipInfo);
        alert(tipInfo);
        return;
      }
      */

//因为我是单独写了一个按钮进行信任站点添加    所以上面的逻辑注释掉了
      alert("请在帮助里添加信任站点");
    }
    
    else{
      //获取可信任站点IP,数字2000没法解释,主要涉及到注册表的问题        这里最好将数字2000改小为10咯,或者比较合理的数字

;i++){  
        try{
          str[i] = WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range" + i + "\\:Range");
        }catch(e){
        }
      }
      var count = true;
      for(var i = 1;i < str.length;i++){  
        if(str[i] == undefined){
          continue;
        }else{
          if(str[i] == hostname){
            count = false;
            break;
          }
        }
      }
      if(count){
        var tipInfo = "IP为" + hostname+"可信任站点不存在!";
        alert(tipInfo);   
        return;
      }
    }
  }

2//信任站点的添加    js代码

try{
                                var WshShell=new ActiveXObject("WScript.Shell");
                            }catch(e){
                                 alert("Error:"+e.message+"。");
                            }
                            //添加信任站点ip     需要加几个,就几个,我加了3个。
                            
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\","");
                            
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\http","2","REG_DWORD");
                            
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\:Range","填自己的域名ip1");

WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\","");

WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\http","2","REG_DWORD");

WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\:Range","填自己的域名ip2");
                            
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range102\\","");

WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range102\\http","2","REG_DWORD");

WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range102\\:Range","填自己的域名ip3");

//修改IE ActiveX安全设置

//    3  internet区域
                            //下载已签名的ActiveX控件:  3=禁用、0=启用、1=提示          
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1001","0","REG_DWORD");
                            //下载未签名的ActiveX控件:
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1004","0","REG_DWORD");
                            //运行ActiveX控件和插件:
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1200","0","REG_DWORD");
                            //对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1201","0","REG_DWORD");
                            //对标记为可安全执行脚本的ActiveX控件执行脚本
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1405","0","REG_DWORD");
                            //ActiveX控件自动提示:ActiveX控件自动提示:
                            WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\2201","0","REG_DWORD");

//禁用xinxp弹出窗口阻止程序

//    WshShell.RegWrite("HKCU\\Software\\Microsoft\\Internet Explorer\\New Windows\\PopupMgr","no");

alert("信任站点设置成功");

05-08 15:32