javascript判斷并獲取注冊(cè)表中可信任站點(diǎn)的方法
本文實(shí)例講述了javascript判斷并獲取注冊(cè)表中可信任站點(diǎn)的方法。分享給大家供大家參考。具體分析如下:
判斷可信任站點(diǎn),首先要在注冊(cè)表中找到可信任站點(diǎn)在注冊(cè)表中的位置,如下:
(1)域名作為可信任站點(diǎn)在注冊(cè)表中的位置:
HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\ZoneMap\\Domains\\
(2)IP作為可信任站點(diǎn)在注冊(cè)表中的位置:
HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\ZoneMap\\Ranges
具體測(cè)試代碼如下:
index.jsp:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>獲取并判斷可信任站點(diǎn)(域名和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="是否是可信站點(diǎn)" id="testRegister" /> </div> </body> </html>
js代碼:
/* * 判斷可信任站點(diǎn)(可信任站點(diǎn)可以為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的正則表達(dá)式 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}$/; //根據(jù)域名判斷是否存在可信站點(diǎn) 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>您加入的可信站點(diǎn)不是合法的可信站點(diǎn),請(qǐng)以<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>您加入的可信站點(diǎn)不是合法的可信站點(diǎn),請(qǐng)以<span style='color:red;'>http://</span>開頭!</div>"; alert(tipInfo); return; }catch(e){} } } if((domainSFlag && domainEFlag) || domainSEFlag){ var tipInfo = "域名為" + hostname + "的可信任站點(diǎn)不存在!"; alert(tipInfo); alert(tipInfo); return; } }else{ //獲取可信任站點(diǎn)IP,數(shù)字2000沒法解釋,主要涉及到注冊(cè)表的問題 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+"可信任站點(diǎn)不存在!"; alert(tipInfo); return } } alert("存在可信任站點(diǎn)!"); } }
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06一文帶你理解微信小程序中RPC通信的實(shí)現(xiàn)
在微信小程序開發(fā)中,要實(shí)現(xiàn)兩個(gè)線程之間的通信是一項(xiàng)重要的任務(wù),所以本文就來(lái)講講如何使用小程序的?postMessage?和?addListener?API?來(lái)實(shí)現(xiàn)在兩個(gè)線程之間進(jìn)行高效的?RPC?通信吧2023-06-06Cpage.js給組件綁定事件的實(shí)現(xiàn)代碼
Cpage.js是一款輕量級(jí)的Mvvm框架,使用TypeScript(JavaScript的超集)開發(fā)。下面通過(guò)本文給大家分享Cpage.js給組件綁定事件的實(shí)現(xiàn)代碼,需要的的朋友參考下吧2017-08-08