搜索可用的Google搜索服务器IP,并将搜索结果缓存入系统Hosts文件内。
提示:此脚本在R5以上版本的EJS脚本IDE工具内可成功解释运行。
clear();
console.info("/**************************版权声明**************************/");
console.info("/* */");
console.info("/*功能描述:查找可用的Google服务器,并将其缓存入系统DNS。 */");
console.info("/*脚本作者:Easton */");
console.info("/*联系邮箱:easton@xiangyadao.com */");
console.info("/*完成时间:2015年2月27日 */");
console.info("/* */");
console.info("/************************************************************/");
var hostsMarkBegin = "#EJS GOOGLE HOSTS BEGIN";
var hostsMarkEnd = "#EJS GOOGLE HOSTS END";
var googleDomains = ["google.com", "www.google.com", "m.google.com", "scholar.google.com", "translate.google.com", "books.google.com", "appengine.google.com", "maps.google.com", "news.google.com", "images.google.com", "finance.google.com", "history.google.com", "drive.google.com", "docs.google.com", "plus.google.com", "play.google.com", "calendar.google.com", "domains.google.com", "code.google.com", "googlecode.com", "v8.googlecode.com", "gyp.googlecode.com", "cloud.google.com", "earth.google.com", "places.google.com", "adwords.google.com", "sites.google.com", "keep.google.com", "support.google.com", "developers.google.com", "spreadsheets.google.com", "video.google.com", "photos.google.com", "wallet.google.com", "groups.google.com", "gmail.com", "www.gmail.com", "m.gmail.com", "m.googlemail.com", "mail-attachment.googleusercontent.com", "www.chrome.com", "developer.chrome.com", "chrome.google.com", "picasa.google.com", "talkgadget.google.com", "toolbar.google.com", "tools.google.com", "inbox.google.com", "apis.google.com", "www.googleapis.com", "android.googleapis.com", "play.googleapis.com", "plus.googleapis.com", "ajax.googleapis.com", "chart.googleapis.com", "fonts.googleapis.com", "redirector-bigcache.googleapis.com", "translate.googleapis.com", "maps.googleapis.com", "content.googleapis.com", "storage.googleapis.com", "commondatastorage.googleapis.com", "static.panoramio.com.storage.googleapis.com", "www.gstatic.com", "ssl.gstatic.com", "csi.gstatic.com", "maps.gstatic.com", "fonts.gstatic.com", "encrypted-tbn0.gstatic.com", "encrypted-tbn1.gstatic.com", "encrypted-tbn2.gstatic.com", "encrypted-tbn3.gstatic.com", "encrypted-tbn4.gstatic.com", "encrypted-tbn5.gstatic.com", "encrypted-tbn6.gstatic.com", "g0.gstatic.com", "g1.gstatic.com", "g2.gstatic.com", "g3.gstatic.com", "g4.gstatic.com", "g5.gstatic.com", "g6.gstatic.com", "g7.gstatic.com", "mt0.gstatic.com", "mt1.gstatic.com", "mt2.gstatic.com", "mt3.gstatic.com", "mt4.gstatic.com", "mt5.gstatic.com", "mt6.gstatic.com", "mt7.gstatic.com", "t0.gstatic.com", "t1.gstatic.com", "t2.gstatic.com", "t3.gstatic.com", "t4.gstatic.com", "t5.gstatic.com", "t6.gstatic.com", "t7.gstatic.com", "1-ps.googleusercontent.com", "2-ps.googleusercontent.com", "3-ps.googleusercontent.com", "4-ps.googleusercontent.com", "www.googleusercontent.com", "oauth.googleusercontent.com", "feedback.googleusercontent.com", "translate.googleusercontent.com", "themes.googleusercontent.com", "webcache.googleusercontent.com", "books.googleusercontent.com", "video.googleusercontent.com", "music-onebox.googleusercontent.com", "music.googleusercontent.com", "blogger.googleusercontent.com", "newsstand.googleusercontent.com", "producer.googleusercontent.com", "code-opensocial.googleusercontent.com", "spreadsheets-opensocial.googleusercontent.com", "www-calENDar-opensocial.googleusercontent.com", "www-fc-opensocial.googleusercontent.com", "www-focus-opensocial.googleusercontent.com", "www-gm-opensocial.googleusercontent.com", "www-kix-opensocial.googleusercontent.com", "www-open-opensocial.googleusercontent.com", "www-opensocial.googleusercontent.com", "www-opensocial-sandbox.googleusercontent.com", "www-oz-opensocial.googleusercontent.com", "a-oz-opensocial.googleusercontent.com", "0-open-opensocial.googleusercontent.com", "1-open-opensocial.googleusercontent.com", "2-open-opensocial.googleusercontent.com", "3-open-opensocial.googleusercontent.com", "0-focus-opensocial.googleusercontent.com", "1-focus-opensocial.googleusercontent.com", "2-focus-opensocial.googleusercontent.com", "3-focus-opensocial.googleusercontent.com", "doc-00-7o-docs.googleusercontent.com", "doc-01-7o-docs.googleusercontent.com", "doc-02-7o-docs.googleusercontent.com", "doc-03-7o-docs.googleusercontent.com", "doc-04-7o-docs.googleusercontent.com", "doc-05-7o-docs.googleusercontent.com", "doc-06-7o-docs.googleusercontent.com", "doc-07-7o-docs.googleusercontent.com", "doc-08-7o-docs.googleusercontent.com", "doc-09-7o-docs.googleusercontent.com", "doc-10-7o-docs.googleusercontent.com", "doc-0a-7o-docs.googleusercontent.com", "doc-0b-7o-docs.googleusercontent.com", "doc-0c-7o-docs.googleusercontent.com", "doc-0d-7o-docs.googleusercontent.com", "doc-0e-7o-docs.googleusercontent.com", "doc-0f-7o-docs.googleusercontent.com", "doc-0g-7o-docs.googleusercontent.com", "doc-0h-7o-docs.googleusercontent.com", "doc-0i-7o-docs.googleusercontent.com", "doc-0j-7o-docs.googleusercontent.com", "doc-0k-7o-docs.googleusercontent.com", "doc-0l-7o-docs.googleusercontent.com", "doc-0m-7o-docs.googleusercontent.com", "doc-0n-7o-docs.googleusercontent.com", "doc-0o-7o-docs.googleusercontent.com", "doc-0p-7o-docs.googleusercontent.com", "doc-0q-7o-docs.googleusercontent.com", "doc-0r-7o-docs.googleusercontent.com", "doc-0s-7o-docs.googleusercontent.com", "doc-0t-7o-docs.googleusercontent.com", "doc-00-bc-docs.googleusercontent.com", "doc-01-bc-docs.googleusercontent.com", "doc-02-bc-docs.googleusercontent.com", "doc-03-bc-docs.googleusercontent.com", "doc-04-bc-docs.googleusercontent.com", "doc-05-bc-docs.googleusercontent.com", "doc-06-bc-docs.googleusercontent.com", "doc-07-bc-docs.googleusercontent.com", "doc-08-bc-docs.googleusercontent.com", "doc-09-bc-docs.googleusercontent.com", "doc-10-bc-docs.googleusercontent.com", "doc-0a-bc-docs.googleusercontent.com", "doc-0b-bc-docs.googleusercontent.com", "doc-0c-bc-docs.googleusercontent.com", "doc-0d-bc-docs.googleusercontent.com", "doc-0e-bc-docs.googleusercontent.com", "doc-0f-bc-docs.googleusercontent.com", "doc-0g-bc-docs.googleusercontent.com", "doc-0h-bc-docs.googleusercontent.com", "doc-0i-bc-docs.googleusercontent.com", "doc-0j-bc-docs.googleusercontent.com", "doc-0k-bc-docs.googleusercontent.com", "doc-0l-bc-docs.googleusercontent.com", "doc-0m-bc-docs.googleusercontent.com", "doc-0n-bc-docs.googleusercontent.com", "doc-0o-bc-docs.googleusercontent.com", "doc-0p-bc-docs.googleusercontent.com", "doc-0q-bc-docs.googleusercontent.com", "doc-0r-bc-docs.googleusercontent.com", "doc-0s-bc-docs.googleusercontent.com", "doc-0t-bc-docs.googleusercontent.com", "doc-00-1s-docs.googleusercontent.com", "doc-01-1s-docs.googleusercontent.com", "doc-02-1s-docs.googleusercontent.com", "doc-03-1s-docs.googleusercontent.com", "doc-04-1s-docs.googleusercontent.com", "doc-05-1s-docs.googleusercontent.com", "doc-06-1s-docs.googleusercontent.com", "doc-07-1s-docs.googleusercontent.com", "doc-08-1s-docs.googleusercontent.com", "doc-09-1s-docs.googleusercontent.com", "doc-10-1s-docs.googleusercontent.com", "doc-0a-1s-docs.googleusercontent.com", "doc-0b-1s-docs.googleusercontent.com", "doc-0c-1s-docs.googleusercontent.com", "doc-0d-1s-docs.googleusercontent.com", "doc-0e-1s-docs.googleusercontent.com", "doc-0f-1s-docs.googleusercontent.com", "doc-0g-1s-docs.googleusercontent.com", "doc-0h-1s-docs.googleusercontent.com", "doc-0i-1s-docs.googleusercontent.com", "doc-0j-1s-docs.googleusercontent.com", "doc-0k-1s-docs.googleusercontent.com", "doc-0l-1s-docs.googleusercontent.com", "doc-0m-1s-docs.googleusercontent.com", "doc-0n-1s-docs.googleusercontent.com", "doc-0o-1s-docs.googleusercontent.com", "doc-0p-1s-docs.googleusercontent.com", "doc-0q-1s-docs.googleusercontent.com", "doc-0r-1s-docs.googleusercontent.com", "doc-0s-1s-docs.googleusercontent.com", "doc-0t-1s-docs.googleusercontent.com", "doc-04-80-docs.googleusercontent.com", "doc-08-6g-docs.googleusercontent.com", "doc-0k-bk-docs.googleusercontent.com", "doc-10-6g-docs.googleusercontent.com", "doc-10-00-docs.googleusercontent.com", "images1-focus-opensocial.googleusercontent.com", "images2-focus-opensocial.googleusercontent.com", "images3-focus-opensocial.googleusercontent.com", "images4-focus-opensocial.googleusercontent.com", "images5-focus-opensocial.googleusercontent.com", "images6-focus-opensocial.googleusercontent.com", "images7-focus-opensocial.googleusercontent.com", "images8-focus-opensocial.googleusercontent.com", "images9-focus-opensocial.googleusercontent.com", "images1-esmobile-opensocial.googleusercontent.com", "images2-esmobile-opensocial.googleusercontent.com", "images3-esmobile-opensocial.googleusercontent.com", "images4-esmobile-opensocial.googleusercontent.com", "images5-esmobile-opensocial.googleusercontent.com", "images6-esmobile-opensocial.googleusercontent.com", "images7-esmobile-opensocial.googleusercontent.com", "images8-esmobile-opensocial.googleusercontent.com", "images9-esmobile-opensocial.googleusercontent.com", "images-docs-opensocial.googleusercontent.com", "images-oz-opensocial.googleusercontent.com", "images-lso-opensocial.googleusercontent.com", "images-blogger-opensocial.googleusercontent.com", "images-pos-opensocial.googleusercontent.com", "lh0.googleusercontent.com", "lh1.googleusercontent.com", "lh2.googleusercontent.com", "lh3.googleusercontent.com", "lh4.googleusercontent.com", "lh5.googleusercontent.com", "lh6.googleusercontent.com", "gp1.googleusercontent.com", "gp2.googleusercontent.com", "gp3.googleusercontent.com", "gp4.googleusercontent.com", "gp5.googleusercontent.com", "gp6.googleusercontent.com", "ci1.googleusercontent.com", "ci2.googleusercontent.com", "ci3.googleusercontent.com", "ci4.googleusercontent.com", "ci5.googleusercontent.com", "ci6.googleusercontent.com", "s1.googleusercontent.com", "s2.googleusercontent.com", "s3.googleusercontent.com", "s4.googleusercontent.com", "s5.googleusercontent.com", "s6.googleusercontent.com", "sp0.googleusercontent.com", "sp1.googleusercontent.com", "sp2.googleusercontent.com", "sp3.googleusercontent.com", "sp4.googleusercontent.com", "sp5.googleusercontent.com", "sp6.googleusercontent.com", "sp7.googleusercontent.com", "sp8.googleusercontent.com", "sp9.googleusercontent.com", "clients1.googleusercontent.com", "clients2.googleusercontent.com", "clients3.googleusercontent.com", "clients4.googleusercontent.com", "clients5.googleusercontent.com", "clients6.googleusercontent.com", "clients7.googleusercontent.com", "lh0.ggpht.com", "lh1.ggpht.com", "lh2.ggpht.com", "lh3.ggpht.com", "lh4.ggpht.com", "lh5.ggpht.com", "lh6.ggpht.com", "nt0.ggpht.com", "nt1.ggpht.com", "nt2.ggpht.com", "nt3.ggpht.com", "nt4.ggpht.com", "nt5.ggpht.com", "nt6.ggpht.com", "yt0.ggpht.com", "yt1.ggpht.com", "yt2.ggpht.com", "yt3.ggpht.com", "yt4.ggpht.com", "yt5.ggpht.com", "yt6.ggpht.com", "gm0.ggpht.com", "gm1.ggpht.com", "gm2.ggpht.com", "gm3.ggpht.com", "gm4.ggpht.com", "gm5.ggpht.com", "gm6.ggpht.com", "geo0.ggpht.com", "geo1.ggpht.com", "geo2.ggpht.com", "geo3.ggpht.com", "geo4.ggpht.com", "geo5.ggpht.com", "geo6.ggpht.com", "clients1.google.com", "clients2.google.com", "clients3.google.com", "clients4.google.com", "clients5.google.com", "clients6.google.com", "0.client-channel.google.com", "1.client-channel.google.com", "2.client-channel.google.com", "3.client-channel.google.com", "4.client-channel.google.com", "5.client-channel.google.com", "6.client-channel.google.com", "7.client-channel.google.com", "8.client-channel.google.com", "9.client-channel.google.com", "10.client-channel.google.com", "11.client-channel.google.com", "12.client-channel.google.com", "13.client-channel.google.com", "14.client-channel.google.com", "15.client-channel.google.com", "16.client-channel.google.com", "17.client-channel.google.com", "18.client-channel.google.com", "19.client-channel.google.com", "20.client-channel.google.com", "21.client-channel.google.com", "22.client-channel.google.com", "23.client-channel.google.com", "24.client-channel.google.com", "25.client-channel.google.com", "26.client-channel.google.com", "27.client-channel.google.com", "28.client-channel.google.com", "29.client-channel.google.com", "uploads.clients.google.com", "uploads.client.google.com", "upload.clients.google.com", "upload.client.google.com", "upload.google.com", "upload.docs.google.com", "upload.photos.google.com", "upload.drive.google.com", "upload.video.google.com", "uploads.code.google.com", "uploads.clients.google.com", "linkhelp.clients.google.com", "feedburner.google.com", "feedproxy.google.com", "0.talkgadget.google.com", "chromoting-host.talkgadget.google.com", "chromoting-oauth.talkgadget.google.com", "chromoting-client.talkgadget.google.com", "maps-api-ssl.google.com", "mapsengine.google.com", "bpui0.google.com", "i18napis.appspot.com", "safebrowsing.google.com", "safebrowsing.clients.google.com", "safebrowsing-cache.google.com", "admin.google.com", "appspot.l.google.com", "browserchannel-docs.l.google.com", "browserchannel-spreadsheets.l.google.com", "browsersync.google.com", "browsersync.l.google.com", "cache.l.google.com", "cache.pack.google.com", "cbk0.google.com", "cbk1.google.com", "cbk2.google.com", "cbk3.google.com", "cbks0.google.com", "cbks1.google.com", "cbks2.google.com", "cbks3.google.com", "dl.google.com", "dl.l.google.com", "dl-ssl.google.com", "encrypted.google.com", "encrypted-tbn.l.google.com", "encrypted-tbn0.google.com", "encrypted-tbn1.google.com", "encrypted-tbn2.google.com", "encrypted-tbn3.google.com", "gg.google.com", "ghs.google.com", "ghs.l.google.com", "ghs46.google.com", "ghs46.l.google.com", "googlecode.l.google.com", "google-public-dns-a.google.com", "google-public-dns-b.google.com", "groups.l.google.com", "investor.google.com", "kh.google.com", "kh.l.google.com", "khm.google.com", "khm.l.google.com", "khm0.google.com", "khm1.google.com", "khm2.google.com", "khm3.google.com", "khmdb.google.com", "khms.google.com", "khms.l.google.com", "khms0.google.com", "khms1.google.com", "khms2.google.com", "khms3.google.com", "lh2.google.com", "lh2.l.google.com", "lh3.google.com", "lh4.google.com", "lh5.google.com", "lh6.google.com", "mars.google.com", "mobilemaps.clients.google.com", "mt.google.com", "mt.l.google.com", "mt0.google.com", "mt1.google.com", "mt2.google.com", "mt3.google.com", "mts.google.com", "mts.l.google.com", "mts0.google.com", "mts1.google.com", "mts2.google.com", "mts3.google.com", "music.google.com", "mw1.google.com", "mw2.google.com", "picasaweb.google.com", "picasaweb.l.google.com", "services.google.com", "sandbox.google.com", "pack.google.com", "sb.google.com", "sb-ssl.google.com", "script.google.com", "security.google.com", "id.google.com", "id.l.google.com", "tbn0.google.com", "tbn1.google.com", "tbn2.google.com", "tbn3.google.com", "voice.google.com", "wifi.google.com", "g.co", "goo.gl", "goto.google.com", "0.docs.google.com", "1.docs.google.com", "2.docs.google.com", "3.docs.google.com", "4.docs.google.com", "5.docs.google.com", "6.docs.google.com", "7.docs.google.com", "8.docs.google.com", "9.docs.google.com", "10.docs.google.com", "0.drive.google.com", "1.drive.google.com", "2.drive.google.com", "3.drive.google.com", "4.drive.google.com", "5.drive.google.com", "6.drive.google.com", "7.drive.google.com", "8.drive.google.com", "9.drive.google.com", "10.drive.google.com", "bks0.books.google.com", "bks1.books.google.com", "bks2.books.google.com", "bks3.books.google.com", "bks4.books.google.com", "bks5.books.google.com", "bks6.books.google.com", "bks7.books.google.com", "bks8.books.google.com", "bks9.books.google.com", "bks10.books.google.com", "spreadsheets0.google.com", "spreadsheets1.google.com", "spreadsheets2.google.com", "spreadsheets3.google.com", "spreadsheets4.google.com", "spreadsheets5.google.com", "spreadsheets6.google.com", "spreadsheets7.google.com", "spreadsheets8.google.com", "spreadsheets9.google.com", "news.google.com.hk", "books.google.com.hk", "accounts.google.com.hk", "clients1.google.com.hk", "encrypted.google.com.hk", "groups.google.com.hk", "id.google.com.hk", "images.google.com.hk", "m.google.com.hk", "maps.google.com.hk", "picasaweb.google.com.hk", "scholar.google.com.hk", "toolbar.google.com.hk", "translate.google.com.hk", "wenda.google.com.hk", "www.google.com.hk", "www.google.com.tw", "accounts.google.com.tw", "maps.google.com.tw", "news.google.com.tw", "books.google.com.tw", "clients1.google.com.tw", "encrypted.google.com.tw", "groups.google.com.tw", "id.google.com.tw", "images.google.com.tw", "m.google.com.tw", "picasaweb.google.com.tw", "scholar.google.com.tw", "toolbar.google.com.tw", "toolbarqueries.google.com.tw", "translate.google.com.tw", "g.cn", "www.g.cn", "www.gstatic.cn", "ditu.google.cn", "maps.google.cn", "gg.google.cn", "id.google.cn", "maps.gstatic.cn", "m.google.cn", "mt.google.cn", "mt0.google.cn", "mt1.google.cn", "mt2.google.cn", "mt3.google.cn", "news.google.cn", "scholar.google.cn", "translate.google.cn", "www.google.cn", "accounts.l.google.com", "csi.l.google.com", "googleapis.l.google.com", "maps.l.google.com", "code.l.google.com", "news.l.google.com", "images.l.google.com", "mobile.l.google.com", "talkx.l.google.com", "talk.l.google.com", "large-uploads.l.google.com", "writely.l.google.com", "writely-china.l.google.com", "writely-com.l.google.com", "www.l.google.com", "www2.l.google.com", "www3.l.google.com", "www4.l.google.com", "ytstatic.l.google.com", "wildcard-talkgadget.l.google.com", "mobile-gtalk.l.google.com", "safebrowsing.cache.l.google.com", "spreadsheets-china.l.google.com", "spreadsheets.l.google.com", "suggestqueries.l.google.com", "video-stats.l.google.com", "sb.l.google.com", "sb-ssl.l.google.com", "scholar.l.google.com", "wifi.l.google.com", "wire.l.google.com", "tools.l.google.com", "photos-ugc.l.google.com", "music-streaming.l.google.com", "googlehosted.l.googleusercontent.com", "www.googledrive.com", "map.google.com", "mage.google.com", "plusone.google.com", "spreadsheet.google.com", "ditu.google.com", "local.google.com", "answers.google.com", "profiles.google.com", "writely.google.com", "buzz.google.com", "ssl.google-analytics.com", "www.google-analytics.com", "googlesource.com", "www.googlesource.com", "android.googlesource.com", "chromium.googlesource.com", "gerrit.googlesource.com", "kernel.googlesource.com", "gwt.googlesource.com"];
#include ~/io/file.ejs
#include ~/io/textfile.ejs
/*
IP辅助对象
*/
var IP =
{
toInt: function(ip)
{
var ipTest =/^(\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])\.(\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])$/;
var xH = "", result = ipTest.exec(ip);
if(!result) return -1;
return (parseInt(result[1]) << 24
| parseInt(result[2]) << 16
| parseInt(result[3]) << 8
| parseInt(result[4]));
},
toString: function(ip)
{
if(ip < 0 || ip > 0xFFFFFFFF){
throw new ArgumentException("参数超过IPV4地址范围。");
}
return (ip >>> 24) + "." + (ip >> 16 & 0xFF) + "." + (ip >> 8 & 0xFF) + "." + (ip & 0xFF);
}
}
var main = function()
{
//开始搜索的IP地址
var start = 1089054986;
//结束搜索的IP地址
var end = 1089077247;
//使用对话框接收值
while(true)
{
var _start = prompt("请输入开始搜索的IP(默认从" + IP.toString(start) + "开始搜索):");
if(_start !== null)
{
_start = IP.toInt(_start);
if(_start === -1)
{
alert("请输入正确的IP地址。");
continue;
}
start = _start;
}
break;
}
console.log("从" + IP.toString(start) + "开始检索。");
while(true)
{
var _count = prompt("请输入要检索的IP个数(默认检索到" + IP.toString(end) + "):");
if(_count !== null)
{
_count = parseInt(_count);
if(isNaN(_count))
{
alert("请输入阿拉伯数字作为要检索的IP个数!");
continue;
}
end = start + _count - 1;
}
break;
}
console.log("检索到" + IP.toString(end) + "结束。");
//为了避免底部http协议视图区域显示http数据封包,加快检索速度这里避免使用内置“http”对象,而是实例化新的http对象。
var h = new Http();
var ipaddr, lastTime = 9999999999;
var ipTotal = (end - start) + 1; //总数
if(!confirm("需要搜索" + ipTotal + "个IP地址,搜索可能会消耗较长的时间,是否继续?"))
{
console.error("用户停止执行脚本。");
return; //退出服务
}
var count = 0;
//开始检索
for(var ip = start; ip <= end; ip++)
{
//计算运行时间
var beginTime = new Date().getTime();
try
{
var temp = IP.toString(ip);
var url = "http://" + temp;
//延时超过300毫秒的服务器都丢掉
var timeout = h.TestIP(temp, 300);
if(timeout != -1)
{
var htmlText = h.get(url, "utf-8");
if(htmlText.indexOf("按回车键进行搜索。") > -1)
{
var endTime = new Date().getTime();
var time = endTime - beginTime;
if(lastTime > time)
{
lastTime = time;
ipaddr = temp;
}
console.info(url + "地址访问耗时:" + time + "毫秒。");
}
else
{
console.error(url + "不是Google搜索服务首页。");
}
}
else
{
console.error(url + "地址访问超时。");
}
}
catch(e)
{
var endTime = new Date().getTime();
var time = endTime - beginTime;
console.error(e.message + "\r\n耗时:" + time + "毫秒。");
}
count++;
console.info("搜索进度:完成" + (count / ipTotal * 100).toFixed(2) + "%。");
}
if(ipaddr === undefined)
{
console.error("未能搜索到可用的Google服务器IP地址。");
return;
}
console.info("最优Google搜索服务器:http://" + ipaddr);
//将最优IP缓存入系统hosts文件
if(confirm("是否将" + ipaddr + "缓存入系统hosts文件?\r\n\r\n警告:缓存过程中请勿停止执行脚本,否则可能造成hosts缓存数据丢失!!!"))
{
var env = System.Environment;
var hosts = env.SystemDirectory + "\\drivers\\etc\\hosts";
if(File.exists(hosts))
{
console.info("当前系统hosts文件路径:" + hosts);
var lines = [];
var i = 0;
//先读取hosts文件
var reader = new TextReader(hosts, "utf-8");
try
{
var skip = false;
while(reader.peek() > -1)
{
var line = reader.readLine();
if(line.indexOf(hostsMarkBegin) === 0)
{
skip = true;
}
if(!skip)
{
lines[i++] = line;
}
if(line.indexOf(hostsMarkEnd) === 0)
{
skip = false;
}
}
lines[i++] = hostsMarkBegin;
for(var j = 0; j < googleDomains.length; j++)
{
lines[i++] = ipaddr + " " + googleDomains[j];
}
lines[i++] = hostsMarkEnd;
}
catch(e)
{
console.error(e.message);
}
finally
{
reader.close();
}
var hosts_backup = env.SystemDirectory + "\\drivers\\etc\\hosts_ejs_backup";
//先备份一份hosts数据
File.copy(hosts, hosts_backup, true);
console.info("已备份hosts文件至:" + hosts_backup);
//写新的hosts文件
File.writeAllLines(hosts, lines, "utf-8");
console.info("已将" + ipaddr + "地址缓存入系统hosts文件。\r\n友情提示:如果未能及时生效请在命令行环境中键入“ipconfig /flushdns”指令刷新DNS。在刷新DNS后还是无效请检查下当前系统的hosts文件是否存在非EJS脚本生成的Google域名DNS缓存,如果存在删除非EJS脚本生成的Google域名DNS缓存即可生效。");
}
else
{
console.error("未找到hosts文件。");
}
}
}
//程序开始执行
main();
建议在执行脚本前先手动备份hosts文件,使用此脚本产生的任何后果由用户自行负责,脚本作者不承担任何后果。