Home>

Judging trusted sites,First, you need to find the trusted site's location in the registry.as follows:

(1) The position of the domain name in the registry as a trusted site:

hkcu \\ software \\ microsoft \\ windows \\ currentversion \\ internetsettings \\ zonemap \\ domains \\

(2) IP's position in the registry as a trusted site:

hkcu \\ software \\ microsoft \\ windows \\ currentversion \\ internetsettings \\ zonemap \\ ranges

The specific test code is as follows:

index.jsp:

<! Doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Get and judge trusted sites (domain name and ip)</title>
<style type="text/css">
.maincontent {
 margin:0 auto;
 margin-top:100px;
 margin-left:100px;
}
</style>
<script type="text/javascript" src="js/testregister.js"></script>
</head>
<body>
<div>
  <input type="button" value="is it a trusted site" />
</div>
</body>
</html>

js code:

/ *
 * Judging Trusted Sites (Trusted sites can be IP addresses or domain names)
 * /
window.onload=function () {
  var btnobj=document.getelementbyid ("testregister");
  btnobj.onclick=function () {
    if (navigator.useragent.indexof ("msie") == -1) {
      alert ("Internet Explorer only!");
      return;
    }
    var hostname=window.location.hostname;
    var wshshell=new activexobject ("wscript.shell");
    // ip regular expression
    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} $/;
    // Determine whether a trusted site exists based on the domain name
    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;
          }
        }
        // Judge its legitimacy
        if (domaineflag &&domainsflag) {
          try {
            wshshell.regread ("hkcu \\ software \\ microsoft \\ windows \\ currentversion \\ internet settings \\ zonemap \\ domains \\" + hostnamesuffix + "\\" + hostnameprefix + "\\ *");
            var tipinfo="<div>The trusted site you joined is not a legitimate trusted site,Please start with<span>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;
        }
        // Judge its legitimacy
        if (domainseflag) {
          try {
            wshshell.regread ("hkcu \\ software \\ microsoft \\ windows \\ currentversion \\ internet settings \\ zonemap \\ domains \\" + hostname + "\\ *");
            var tipinfo="<div>The trusted site you joined is not a legitimate trusted site,Please start with<span>http://</span> ;!</div>";
            alert (tipinfo);
            return;
          } catch (e) {}
        }
      }
      if ((domainsflag &&domaineflag) || domainseflag) {
        var tipinfo="Trusted site with domain name + hostname +" does not exist! ";
        alert (tipinfo);
        alert (tipinfo);
        return;
      }
    } else {
      // Get trusted site ip, the number 2000 cannot be explained,Problems that mainly involve the registry
      var str=[];
      for (var i=1;i<2000;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 is" + hostname + "trusted site does not exist!";
        alert (tipinfo);
        return
      }
    }
    alert ("Trusted site exists!");
  }
}
  • Previous Detailed dictionary usage examples in python
  • Next JS array array element addition and deletion method code example
  • Trends