Javascript judges and obtains trusted sites in the Registry (domain names and IP addresses can be used)

Source: Internet
Author: User
Tags ranges

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! ");}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.