Skip to content

Instantly share code, notes, and snippets.

@alphatr
Created March 23, 2015 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alphatr/64251dc5a2daf17eab60 to your computer and use it in GitHub Desktop.
Save alphatr/64251dc5a2daf17eab60 to your computer and use it in GitHub Desktop.
PAC
/**
* PAC 文件
* By:Alpha
*/
/* global isInNet, isPlainHostName, dnsResolve, shExpMatch */
function FindProxyForURL(url, host) {
/* 返回代理 */
var proxy = 'PROXY 192.168.0.88:8080; SOCKS 192.168.0.88:8080; DIRECT;',
direct = "DIRECT;", i, domain;
var BLACK_LIST = [
/* instagram */
"instagram.com",
"google.com",
/* v2ex */
"v2ex.com",
/* github */
"github.com"
];
url = url.toLowerCase();
host = host.toLowerCase();
// 本机
if (host == "127.0.0.1") {
return direct;
}
// 简单域名
if (isPlainHostName(host)) {
return direct;
}
// 内网
var ip = dnsResolve(host);
if (isInNet(ip, "10.0.0.0", "255.0.0.0") || isInNet(ip, "192.168.0.0", "255.255.0.0")) {
return direct;
}
// 判断黑名单
for (i = 0; i < BLACK_LIST.length; i++) {
domain = '*' + BLACK_LIST[i];
if (shExpMatch(host, domain)) {
return proxy;
}
}
return direct;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment