The examples in this article describe the methods that JavaScript can take to determine and obtain trusted sites in the registry. Share to everyone for your reference. The specific analysis is as follows:
To determine the trusted site, first find the location of the trusted site in the registry in the registry, as follows:
(1) The location of the domain name as a trusted site in the registry:
Hkcusoftwaremicrosoftwindowscurrentversioninternetsettingszonemapdomains
(2) IP as the location of the trusted site in the registry:
Hkcusoftwaremicrosoftwindowscurrentversioninternetsettingszonemapranges
The specific test code is as follows:
INDEX.JSP:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 |
<! DOCTYPE html> |
JS Code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
* * To judge the trusted site (can be trusted site for IP address can also be domain name)/window.onload = function () {var btnobj = document.getElementById ("Testregister"); btn Obj.onclick = function () {if (Navigator.userAgent.indexOf ("msie") = = 1) {alert ("Support IE browser only!") "); Return var hostname = Window.location.hostname; var WshShell = new ActiveXObject ("Wscript.Shell"); The regular expression of IP, var reg =/^ (d{1,2}|1dd|2[0-4]d|25[0-5]) (. ( D{1,2}|1DD|2[0-4]D|25[0-5])) {3}$/; Determine if there is a trusted site 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 ("hkcusoftwaremicrosoftwindowscurrentversioninternet settingszonemapdomains" + hostname + "http "); } catch (e) {Domaineflag = true;} if (Domaineflag) {try{WshShell.RegRead ("HKCUSOFTWAREMICROSOFTWIndowscurrentversioninternet Settingszonemapdomains "+ Hostnamesuffix +" "+ Hostnameprefix +" http ");} catch (e) {Domainsflag = true;}} Judge its legality if (Domaineflag && domainsflag) {try{WshShell.RegRead (" Hkcusoftwaremicrosoftwindowscurrentversioninternet Settingszonemapdomains "+ Hostnamesuffix +" "+ HostnamePrefix +" * " ); var tipinfo = "<div> you join a trusted site that is not a legitimate trusted site, please <span style= ' color:red; ' >http://</span> start! </div> "; alert (tipinfo); Return }catch (e) {}}}else{try{WshShell.RegRead ("Hkcusoftwaremicrosoftwindowscurrentversioninternet Settingszonemapdomains "+ hostname +" http "); }catch (e) {Domainseflag = true;}//Judge its legality if (Domainseflag) {try{WshShell.RegRead (" Hkcusoftwaremicrosoftwindowscurrentversioninternet settingszonemapdomains "+ hostname +" * "); var tipinfo = "<div> you join a trusted site that is not a legitimate trusted site, please <span style= ' color:red; ' >http://</span> start! </div> "; alert (tipinfo); Return }catch (e) {}}} if (Domainsflag && domaineflag) | | domainseflag{var tipinfo = "The domain name is" + hostname + "Can not be trusted site!) "; alert (tipinfo); alert (tipinfo); Return }else{//Get trusted site IP, number 2000 can not explain, mainly related to the registry problem var str = []; for (var i = 1;i < 2000;i++) {try{Str[i] = WshShell.RegRead (" Hkcusoftwaremicrosoftwindowscurrentversioninternet Settingszonemaprangesrange "+ 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+" can be trusted site does not exist! "; alert (tipinfo); return} alert ("There is a trustworthy site!") "); } } |
The
wants this article to help you with your JavaScript programming.