DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> javascript判斷並獲取注冊表中可信任站點的方法
javascript判斷並獲取注冊表中可信任站點的方法
編輯:JavaScript綜合知識     

   本文實例講述了javascript判斷並獲取注冊表中可信任站點的方法。分享給大家供大家參考。具體分析如下:

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

  (1)域名作為可信任站點在注冊表中的位置:

  HKCUSoftwareMicrosoftWindowsCurrentVersionInternetSettingsZoneMapDomains

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

  HKCUSoftwareMicrosoftWindowsCurrentVersionInternetSettingsZoneMapRanges

  具體測試代碼如下:

  index.jsp:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <!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代碼:

  ?

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 32 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 /* * 判斷可信任站點(可信任站點可以為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的正則表達式 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}$/; //根據域名判斷是否存在可信站點 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; } } //判斷其合法性 if(domainEFlag && domainSFlag){ try{ WshShell.RegRead("HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZoneMapDomains" + hostnameSuffix + "" + hostnamePrefix + "*"); var tipInfo = "<div>您加入的可信站點不是合法的可信站點,請以<span style='color:red;'>http://</span>開頭!</div>"; alert(tipInfo); return; }catch(e){} } }else{ try{ WshShell.RegRead("HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZoneMapDomains" + hostname + "http"); }catch(e){ domainSEFlag = true; } //判斷其合法性 if(domainSEFlag){ try{ WshShell.RegRead("HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZoneMapDomains" + 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("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為" + hostname+"可信任站點不存在!"; alert(tipInfo); return } } alert("存在可信任站點!"); } }

  希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved