Proxy Auto-Configuration (PAC) scripts
PAC files are written in JavaScript. They are pretty handy if you have more than 1 proxy server.
The basic structure is:
function FindProxyForURL(url, host){
return "PROXY proxyserver:8080";}
But if you have intranet sites you don't want them to go through the proxy. Then you can add some exceptions and make all plain hostnames bypass the proxy.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080";}
You can also add any address or domain as an exception.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
if (shExpMatch(url,"*google.com*") ||
shExpMatch(url,"*microsoft.com*"))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080";}
If you have more than 1 proxy you can specify all of them. In the next example it will try the first proxy, if it is unavailable it will try the second, if it is also unavailable it connects direct to the internet.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
if (shExpMatch(url,"*google.com*") ||
shExpMatch(url,"*microsoft.com*"))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080; PROXY proxyserver2:8080; DIRECT";}
The basic structure is:
function FindProxyForURL(url, host){
return "PROXY proxyserver:8080";}
But if you have intranet sites you don't want them to go through the proxy. Then you can add some exceptions and make all plain hostnames bypass the proxy.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080";}
You can also add any address or domain as an exception.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
if (shExpMatch(url,"*google.com*") ||
shExpMatch(url,"*microsoft.com*"))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080";}
If you have more than 1 proxy you can specify all of them. In the next example it will try the first proxy, if it is unavailable it will try the second, if it is also unavailable it connects direct to the internet.
function FindProxyForURL(url, host){
if (isPlainHostName(host))
return "DIRECT";
if (shExpMatch(url,"*google.com*") ||
shExpMatch(url,"*microsoft.com*"))
return "DIRECT";
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
return "PROXY proxyserver:8080; PROXY proxyserver2:8080; DIRECT";}
No comments:
Post a Comment