javascript判斷並擷取註冊表中的可信任網站(可以為網域名稱和IP)

來源:互聯網
上載者:User

 判斷可信任網站,首先要在註冊表中找到可信任網站在註冊表中的位置,如下:

 (1)網域名稱作為可信任網站在註冊表中的位置:

 HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings

\\ZoneMap\\Domains\\

 

(2)IP作為可信任網站在註冊表中的位置:

 HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings

\\ZoneMap\\Ranges

 

具體測試代碼如下:

index.jsp

<!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>擷取並判斷可信任網站(網域名稱和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 class="mainContent">            <input type="button" value="是否是可信網站" id="testRegister" />        </div>    </body></html>

js代碼:

/* * 判斷可信任網站(可信任網站可以為IP地址也可以為網域名稱) */window.onload = function(){    var btnObj = document.getElementById("testRegister");    btnObj.onclick = function(){        if(navigator.userAgent.indexOf("MSIE") == -1){              alert("只支援IE瀏覽器!");            return;        }        var hostname = window.location.hostname;        var WshShell = new ActiveXObject("WScript.Shell");        //IP的Regex        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;            }        }else{            //擷取可信任網站IP,數字2000沒法解釋,主要涉及到註冊表的問題            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為" + hostname+"可信任網站不存在!";                alert(tipInfo);                   return            }        }        alert("存在可信任網站!");    }}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.