Created
March 23, 2015 06:53
-
-
Save alphatr/64251dc5a2daf17eab60 to your computer and use it in GitHub Desktop.
PAC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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