Proxy auto-config,简称PAC,是用于定义浏览器如何自动选择适当的代理服务器来访问一个网址。因此,使用PAC文件来定义代理的话,可以方便的实现
- 实现代理的动态切换(fail-over)
- 对于不同的url或是ip range,配置不同的server,加速网络访问速度
- 对于proxy,可以实现负载均衡
一个PAC文件是一个至少定义了一个JavaScript函数的文本文件。这个函数FindProxyForURL(url, host)。有2个参数:url是一个对象的URL,host是一个由这个URL所指向的主机名。返回值是代理的配置。
function FindProxyForURL(url, host) {
return "PROXY proxy.example.com:8080; DIRECT";
}
这个函数返回值告诉浏览器优先通过代理服务器proxy.example.com的8080端口来获取所有的页面。如果这个代理服务器没有反应,浏览器不使用代理服务器直接访问。多个代理之间用分号(;)分隔。
PAC函数
PAC配置可以使用一系列内置的函数。这些函数最早来源于Netscape公司出的规范。Netscape对于技术来说,是个伟大的公司,可惜的是其的商业化能力。
[list]
dnsDomainIs
Evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual hostnames.
if (dnsDomainIs(host, ".google.com"))
return "DIRECT";
shExpMatch
Will attempt to match hostname or URL to a specified shell expression, and returns true if matched.
if (shExpMatch(url, "*.local"))
return "DIRECT";
if (shExpMatch(host, "vpn.domain.com") ||
shExpMatch(url, "http://abcdomain.com/folder/*"))
return "DIRECT";
isInNet
This function evaluates the IP address of a hostname, and if within a specified subnet returns true. If a hostname is passed the function will resolve the hostname to an IP address.
if (isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0"))
return "DIRECT";
myIpAddress
Returns the IP address of the host machine.
if (isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0"))
return "PROXY 10.10.5.1:8080";
dnsResolve
Resolves hostnames to an IP address. This function can be used to reduce the number of DNS lookups.
if (isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0") ||
isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0") ||
isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0"))
return "DIRECT";
isPlainHostName
This function will return true if the hostname contains no dots, e.g. http://intranet
Useful when applying exceptions for internal websites, e.g. may not require resolution of a hostname to IP address to determine if local.
if (isPlainHostName(host))
return "DIRECT";
localHostOrDomainIs
Evaluates hostname and only returns true if exact hostname match is found.
if (localHostOrDomainIs(host, "www.google.com"))
return "DIRECT";
这可以包括google.com所以子的domain。
if (localHostOrDomainIs(host, ".google.com"))
return "DIRECT";
isResolvable
Attempts to resolve a hostname to an IP address and returns true if successful. WARNING – This may cause a browser to temporarily hang if a domain isn’t resolvable.
if (isResolvable(host))
return "PROXY proxy1.example.com:8080";
dnsDomainLevels
This function returns the number of DNS domain levels (number of dots) in the hostname. Can be used to exception internal websites which use short DNS names, e.g. http://intranet
if (dnsDomainLevels(host) > 0)
return "PROXY proxy1.example.com:8080";
else return "DIRECT";
weekdayRange
Allows rules to be time based, e.g. only return a proxy during specific days.
if (weekdayRange("MON", "FRI")) return "PROXY proxy1.example.com:8080";
else return "DIRECT";
dateRange
Allows rules to be time based, e.g. only return a proxy during specific months.
if (dateRange("JAN", "MAR")) return "PROXY proxy1.example.com:8080";
else return "DIRECT";
timeRange
Allows rules to be time based, e.g. only return a proxy during specific hours.
if (timeRange(8, 18)) return "PROXY proxy1.example.com:8080";
else return "DIRECT";
alert
The alert() function is not specified in the original PAC specification, although support for this is included in Internet Explorer and Firefox.The function can be used to output the value of a variable or result of a function in a manner that is viewable by the end-user. This can be useful for troubleshooting PAC file rule issues.
resolved_host = dnsResolve(host);
alert(resolved_host);
[/list]
注意
Firefox或Internet Explorer只支持系统缺省编码的PAC文件,不支持Unicode编码的PAC文件,所以在编写PAC文件的时候要注意文件的编码方式。
分享到:
相关推荐
WinHTTP Web Proxy Auto-Discovery Service 服务处于 停止 状态还有,我的服务器没有使用WEB代理和防火墙客户端。
还是非常好的 外国资料 希望能对大家有用
为了方便大家下载:https://github.com/PortSwigger/proxy-auto-config.git
Laravel开发-laravel-proxy-config Laravel 4的配置代理。
influx-proxy-2.5.7-linux-amd64.tar.gz
mysql-proxy-0.8.5-windows-x86-32bit. 官网下载挺麻烦的,直接下载下来备份。 mysql proxy for windows
解决办法: 禁用服务 Win2003 WinHTTP Web Proxy Auto-Discovery Service。 双击右下角的时间,在“Internet时间”选项卡中将“自动与 Internet 时间服务器同步”选项去掉。 您可能感兴趣的文章:在VPS上用3Proxy...
charles 解压就能用 charles-proxy-4.5.6-win64
PACtory是一种高度可定制的方式,用于通过动态创建的.pac文件处理代理配置设置,该文件也称为“ Windows代理自动检测”或“ wpad.dat”文件,该文件在客户端请求时动态生成。 。
代理服务器 BrowserMob Proxy,BrowserMob Proxy 简称 BMP,可以这么说,BMP 绝对是为 Selenium 为生的,Selenium + BMP 的完美搭配,可以实现很多你绝对想象不出来的功能
charles-proxy-4.5.6-win64.msi
PAC(Proxy Auto-Config)文件是一种用于自动配置网络的文件。它是一种使用 JavaScript 语言编写的文本文件,用于指定在访问特定网址时应使用哪个代理服务器或直接连接。PAC 文件主要用于在企业和组织网络中实现代理...
赠送jar包:hadoop-yarn-server-web-proxy-2.6.0.jar; 赠送原API文档:hadoop-yarn-server-web-proxy-2.6.0-javadoc.jar; 赠送源代码:hadoop-yarn-server-web-proxy-2.6.0-sources.jar; 赠送Maven依赖信息文件:...
browsermob-proxy-2.1.4,与selenium一起进行爬虫,获取network中的链接资源
Proxy-SwitchyOmega-Chromium-2.5.15.zip
一个很好的抓包工具,请大家惠存!!!一个很好的抓包工具,请大家惠存!!!
charles-proxy-4.2.8-win64.msi
docker-letsencrypt-nginx-proxy-companion-examples, 结合 Docker gen和 letsencrypt Nginx 代理伙伴的示例 docker-letsencrypt-nginx-proxy-companion-examples这个库是使用 nginx代理插件, docker gen和 docker-...
java运行依赖jar包
proxy4safari-pac-文件 个人配置文件 注意:如果您为您的用例复制我的配置文件,请更改端口号。