Skip to content

Instantly share code, notes, and snippets.

@vqiu
Forked from alphatr/proxy.pac
Last active November 10, 2018 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vqiu/d1b1e1fa97e9a1871f43344f34e721e5 to your computer and use it in GitHub Desktop.
Save vqiu/d1b1e1fa97e9a1871f43344f34e721e5 to your computer and use it in GitHub Desktop.
PAC
function FindProxyForURL(url, host) {
var proxy = "SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT";
var black = "PROXY 127.0.0.1:65535";
var direct = "DIRECT";
var PROXY_LIST = [
"instagram.com",
"google.com",
"facebook.com",
"github.com",
"httpbin.org",
];
/*
var BLACK_LIST = [
"jd.com",
"taobao.com",
"dangdang.com",
"tmall.com",
"pinduoduo.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 < PROXY_LIST.length; i++) {
domain = '*' + PROXY_LIST[i];
if (shExpMatch(host, domain)) {
return proxy;
}
}
/*
for (i = 0; i < BLACK_LIST.length; i++) {
domain = '*' + BLACK_LIST[i];
if (shExpMatch(host, domain)) {
return black;
}
}
*/
return direct;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment