To determine a trusted site, you must first find the location of the trusted site in the Registry, as shown below:
(1) Position of the domain name in the registry as a trusted site:
Hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ internetsettings
\ Zonemap \ Domains \\
(2) ip address as the location of the trusted site in the registry:
Hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ internetsettings
\ Zonemap \ ranges
The specific test code is as follows:
Index. jsp
<! Doctype HTML>
JS Code:
/** Determine a trusted site (a trusted site can be an IP address or a domain name) */window. onload = function () {var btnobj = document. getelementbyid ("testregister"); btnobj. onclick = function () {If (navigator. useragent. indexof ("MSIE") =-1) {alert ("only supports ie browsers! "); Return;} var hostname = Window. location. hostname; var wshshell = new activexobject ("wscript. shell "); // ip address 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 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 ;}} // determine its validity 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 valid trusted site. Use <span style = 'color: red; '> HTTP: /// </span> starts! </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;} // determine its validity 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 valid trusted site. Please start with <span style = 'color: red; '> http: // </span>! </Div> "; alert (tipinfo); Return ;}catch (e) {}} if (domainsflag & domaineflag) | domainseflag) {var tipinfo = "a trusted site with the domain name" + hostname + "does not exist! "; Alert (tipinfo); Return ;}} else {// gets the IP address of a trusted site. The number 2000 cannot be explained, mainly related to 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] = Ho Stname) {COUNT = false; break ;}}if (count) {var tipinfo = "IP:" + hostname + "the trusted site does not exist! "; Alert (tipinfo); return} alert (" a trusted site exists! ");}}