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


参考文档

  1. 代理(Proxy)和VPN的区别
  2. Proxy_Auto-Configuration_PAC_file
  3. 保留的 IP 地址汇总表
  4. 判断某个IP是公共IP还是保留IP
  5. IPV4的保留地址汇总
posted @ 2022-10-27 20:13  jingjingxyk  阅读(478)  评论(0编辑  收藏  举报