proxy.pac文件的编写例子
proxy.pac
pac文件内容其实是一段javascript 代码
let proxy_domains = [
"translate.googleapis.com"
];
function go_proxy(url, host) {
return proxy_domains.find((currentValue, index, arr) => {
if (host.indexOf(currentValue) !== -1) {
return true;
}
return false;
}, host);
}
function FindProxyForURL(url, host) {
if (isPlainHostName(host)) {
return "DIRECT";
}
if (
isInNet(host, "192.168.0.0", "255.255.0.0") ||
isInNet(host, "127.0.0.0", "255.0.0.0") ||
isInNet(host, "10.0.0.0", "255.0.0.0") ||
isInNet(host, "172.16.0.0", "255.240.0.0")
) {
return "DIRECT";
}
if (go_proxy(url, host)) {
return "PROXY 127.0.0.1:8016; SOCKS5 127.0.0.1:2000; DIRECT";
}
return "DIRECT";
}
使用
cp proxy.js proxy.pac
python3 -m http.server 8000
# use proxy.pac
http://localhost:8000/proxy.pac