用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - javascript代码库

白名单域名 黑名单域名 过滤

2013-07-11 作者: 免费源代码下载整理举报

[javascript]代码库

/*
 * 本 PAC 地址:http://t.xd.cn/ 欢迎内部传播
 * 本 PAC 通过 Dropbox 更新。需要编辑权限的,可以告诉你的 Dropbox 帐号,Share 一下就好了
 *
 * 建议复制一个临时文件来修改,用 jslint 检查语法
 * Mac 下安装 jslint
 * brew install jslint
 * jslint -process index.pac
 * 没装 brew 的,先装个:/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)
 *
 * 某些黑名单域名,用我的DNS服务器的话,就会解析到境内IP,解析到这些IP时,不需要翻墙
 * DNS 服务器:180.153.139.245 180.153.139.246 上海电信服务器,网通用户请勿使用,否则境内很多大网站的 CDN 会把你分配到上海电信附近的服务器
 *
 * BTW,如果需要根据IP来翻墙,可以用 http://t.xd.cn/ip 但是IP列表非常多,客户端解析会很耗CPU
 *
 * by xdanger@gmail.com, 最近更新:2012.03.03 1:30
 */
function FindProxyForURL(url, host) {
    var _socks_us = "SOCKS 115.182.64.62:8881";
    var _socks_hk = "SOCKS 115.182.64.62:8883";
    var _socks_tw = "SOCKS t.xd.cn:8888";
    var _http_prx = "PROXY t.xd.cn:8890";
    var _wl_dom = [ ".verycd.com", ".baidu.com", ".qq.com" ];
    var _wl_url = [];
    var _wl_add = [ ['203.208.0.0', '255.255.0.0'] ];
    // 麻烦添加网站前先搜索一下,所有 .jp/.tw/.hk/.cc 域名已经都进去了
    var _bl_dom = [
            ".10gbfreehost.com",
            ".1bao.org",
            ".500px.com",
            ".500px.net",
            ".aboluowang.com",
            ".addthis",
            ".aircrack-ng.org",
            ".amazon.com",
            ".amazonaws.com",
            ".amazonwebservices.com",
            ".appspot.com",
            ".asahichinese.com",
            ".avhappy.com",
            ".bang-olufsen.com",
            ".bao.li",
            ".battle.net",
            ".bbc.co.uk",
            ".bit.ly",
            ".blogger.com",
            ".blogsmithmedia.com",
            ".blogspot.com",
            ".bullogger.com",
            ".caucho.com",
            ".cc",
            ".chinagfw.org",
            ".cl.ly",
            ".cmule.com",
            ".cmule.info",
            ".cmule3.info",
            ".cmule5.info",
            ".cnn.com",
            ".curse.com",
            ".daahoo.com",
            ".dajiyuan.com",
            ".davebalmain.com",
            ".delicious.com",
            ".demonoid",
            ".developer.android.com",
            ".dropbox.com",
            ".dropboxatwork.com",
            ".echofon.com",
            ".engadget.com",
            ".epochtimes.com",
            ".evernote.com",
            ".facebook.com",
            ".facebook.net",
            ".fbcdn.net",
            ".fc2.com",
            ".feedburner.com",
            ".feedly.com",
            ".ff.im",
            ".flickr.com",
            ".foursquare",
            ".freakshare.com",
            ".freemorenews.com",
            ".fsck.com",
            ".funp.com",
            ".ggpht.com",
            ".git-scm.com",
            ".gitcasts.com",
            ".golang.org",
            // Google 解析到的是境内IP,不需要代理
            // 而且国外服务器无法访问Google境内的IP,所以用了代理反而会连不上!
            // 如果有个别域名确实需要代理,请加具体域名
            //".google.com",
            ".googleusercontent.com",
            ".googlevideo.com",
            ".googlevideo.com.cn",
            ".grandfg.com",
            ".greasespot.net",
            ".gstatic.com",
            ".hdbits.org",
            ".hecaitou.net",
            ".hellotxt",
            ".hellowtext.com",
            ".hemidemi.com",
            ".hermanmiller.com",
            ".hk",
            ".html5quintus.com",
            ".hulu.com",
            ".ikan.pptv.com",
            ".imageporter.com",
            ".imageshack.us",
            ".imdb.com",
            ".imdb.com",
            ".img.ly",
            ".instagr.am",
            ".instwall",
            ".internic.com",
            ".itunes.apple.com",
            ".iyin.net",
            ".j.mp",
            ".jp",
            ".kenengba.com",
            ".lighthouseapp.com",
            ".live.com",
            ".livejournal.com",
            ".loveyahu.nu",
            ".mail-archive.com",
            ".mediafire.com",
            ".mindmeister.com",
            ".mitbbs.com",
            ".mobile01.com",
            ".5i01.com",
            ".myblog.yahoo.com",
            ".myminicity.com",
            ".namecheap.com",
            ".nanorails.com",
            ".netshelter.net",
            ".opera.com",
            ".pandora.com",
            ".path.com",
            ".peacehall.com",
            ".pixnet.net",
            ".photoload.ru",
            ".pinyuan001.com",
            ".playup.com",
            ".plurk.com",
            ".progit.org",
            ".queenlook.com",
            ".rfa.org",
            ".rubygems.org",
            ".safaribooksonline.com",
            ".secretchina.com",
            ".sgp.cm",
            ".sourceforge.net",
            ".staticflickr.com",
            ".supersized.org",
            ".t.co",
            ".technorati.com",
            ".thepiratebay.org",
            ".torproject.org",
            ".tumblr.com",
            ".tw",
            ".tw.yahoo.com",
            ".twitpic",
            ".twitter.com",
            ".tweetdeck.com",
            ".twitterfeed.com",
            ".typepad.com",
            ".ultraxs.com",
            ".uncyclopedia",
            ".ustream.tv",
            ".uwants.com",
            ".v2ex.com",
            ".vimeo.com",
            ".vimeocdn.com",
            ".voanews.com",
            ".vox.com",
            ".w3schools.com",
            ".wenxuecity.com",
            ".wikileaks.org",
            ".wikimedia.org",
            ".wikinews.org",
            ".wikipedia.org",
            ".wunderlist.com",
            ".wordpress.com",
            ".wp.com",
            ".wuala.com",
            ".xuite.net",
            ".xys.org",
            ".xysblogs.org",
            ".yfrog.com",
            ".yimg.com",
            ".yindows.com",
            ".youtube.com",
            ".zaobao.com",
            ".zaozon.com",
            ".ziphone.org",
            ".zuo.la",
            ".zuola.com",
            "asahichinese.com",
            "bit.ly",
            "delicious.com",
            "fbcdn-photos-a.akamaihd.net",
            "fbcdn-profile-a.akamaihd.net",
            "git-scm.com",
            "html5quintus.com",
            "instagr.am",
            "path.com",
            "plus.google.com",
            "progit.org",
            "sgp.com",
            "twitter.com",
            "t.co",
            "vimeo.com",
            "wunderlist.com",
            "wordpress.com"
    ];
    // 尽量加域名,匹配速度会快,节约CPU。不行的再加URL模糊匹配
    var _bl_url = [ "*/search?q=cache:*" ];
    var _bl_add = [ ["180.168.41.0", "255.255.255.0"], ["66.6.36.36", "255.255.255.254"], ["74.125.31.103", "255.255.0.0"] ];
    var i = 0;
    // 判断境内IP
    var ip = dnsResolve(host);
    for (i = 0; i < _wl_add.length; i++) {
        if (isInNet(ip, _wl_add[i][0], _wl_add[i][1])) { return "DIRECT"; }
    }
    // 白名单域名
    for (i = 0; i < _wl_dom.length; i++) {
        if (dnsDomainIs(host, _wl_dom[i])) { return "DIRECT"; }
    }
    // 白名单URL
    for (i = 0; i < _wl_url.length; i++) {
        if (shExpMatch(url, _wl_url[i])) { return "DIRECT"; }
    }
    // Dropbox 需要用 http 代理才能即时获取更新
    /* HTTP 代理好像不好用
    var _http_dom = [ '.dropbox.com' ];
    for (i = 0; i < _http_dom.length; i++) {
        if (dnsDomainIs(host, _http_dom[i])) { return _http_prx; }
    }
    */
    // 使用美国代理
    var _us_dom = [ '.pandora.com' ];
    for (i = 0; i < _us_dom.length; i++) {
        if (dnsDomainIs(host, _us_dom[i])) { return _socks_us; }
    }
    // 黑名单域名
    for (i = 0; i < _bl_dom.length; i++) {
        if (dnsDomainIs(host, _bl_dom[i])) { return _http_prx; }
    }
    // 黑名单URL
    for (i = 0; i < _bl_url.length; i++) {
        if (shExpMatch(url, _bl_url[i])) { return _http_prx; }
    }
    for (i = 0; i < _bl_add.length; i++) {
        if (isInNet(ip, _bl_add[i][0], _bl_add[i][1])) { return _http_prx; }
    }
    // 默认
    return "DIRECT";
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...