PAC Automatic Proxy

Source: Internet
Author: User

Recently read the HTTP authoritative guide in the introduction of the agent, there are many agents, today, mainly to say automatic proxy PAC

The PAC (Proxy Auto Config) is a script, and by writing this script, we can let the system determine which Proxy to use for online

The PAC file is in plain text format and is actually a JavaScript file.

Be sure to define the Function FindProxyForURL in the PAC file
The parameter URL is the URL that the user enters, and the parameter host is the host name in the URL. function FindProxyForURL (URL, host) {...}


This method needs to return a proxy dynamic group


Value Describe Sample Example
DIRECT Direct online and not via Proxy return "DIRECT";
PROXY Host:port Using the specified Proxy servo machine return "192.168.22.22:3128;192.168.22.23:3128";
SOCKS Host:port Using the specified Socks servo machine return "SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT; ";

I'll explain the following example (in fact, the order problem):

1: First through the ' SOCKS5 127.0.0.1:1080 ' This SOCKS5 proxy connection

2: If 1 does not, through the ' SOCKS 127.0.0.1:1080 ' This SOCKS proxy connection

3: If the front is not, then directly connect not to go Agent


Complete case

Case one:

var domains = {     "google.com":  1 ,     "facebook.com": 1,     "bing.com": 1};var proxy =   "socks5 127.0.0.1:1080; socks 127.0.0.1:1080; direct;"; var direct =  ' direct; '; Function findproxyforurl (url, host)  {    var lastPos;     do {        if  (Domains.hasownproperty (host))  {            return proxy;         }        lastPos =  Host.indexof ('. ')  + 1;        host = host.slice (LastPos);     } while  (lastpos >= 1);     return direct;} 


Case TWO:

function FindProxyForURL (URL, host) {if (shExpMatch (URL, "*.google.com/*")) {return ' PROXY 192.168.22.22:3128 '     ;     } if (shExpMatch (URL, "*.wikipedia.com:*/*")) {return "SOCKS5 www.vincentguo.cn:1080";     } if (isInNet (host, "10.0.0.0", "255.0.0.0")) {return "DIRECT"; } return "DIRECT; PROXY 192.168.22.22:3128; SOCKS5 www.vincentguo.cn:1080 "; }


A PAC file can be used with JavaScript functions
isPlainHostName The host name that the isPlainHostName (host) host obtains from the URL. This Function will determine if the host is not domain-inclusive. If it is, return true, or return False if it is included.
dnsDomainIs Host name of the dnsDomainIs (host domain) host that was obtained by the URL. Domain that is specified by domain. This Function will determine if the host is part of domain domains. If it is, then return true; no, return false.
localHostOrDomainIs localHostOrDomainIs (host, Hostdom) hosts the hostname obtained by the URL. Hostdom the full domain name. This Function determines whether the host is hostdom, or if host is the hostname of hostdom. If it is, then return true; no, return false.
Isresolvable The host name that the isresolvable (host) host obtains from the URL. This Function will attempt to resolve the host through DNS, return True if the parse succeeds, or return false.
isInNet isInNet (host, pattern, mask) host name, which can be Domain name or IP. If it is Domain Name, the IP is detected through DNS. Pattern IP. Mask corresponds to the mask of pattern. This Function will host whether it is within the specified IP range, or return True if it is, otherwise return false.
Dnsresolve

Dnsresolve host name to be clear through DNS. This Function parses the Host,return value through DNS as the result of parsing.

myIpAddress myIpAddress () This Function will return the IP address of the computer where the browser is located.
dnsDomainLevels The host name that the dnsDomainLevels (host) host obtains from the URL. This Function will return the host's Domain layer number (the number of points).
shExpMatch shExpMatch (str, shexp) STR is being compared to a string. Shexp the conditions of the comparison. This Function is more than the SHEXP expression for str (this expression is shell expression and not regular expressions). If it is, return true; otherwise return false.
Weekdayrange
DateRange
Timerange



I use the FQ software is to use PAC, see the effect



Reference: http://findproxyforurl.com/pac-functions/


Original address: PAC Auto Agent
Tags: PAC http proxy shadowsocks socks SOCKS5

Smart recommendations
    • Mysql Common Command Set
    • Enable NFS file system to promote Vagrant shared directory performance
    • Squid Operation Practice
    • Ubuntu AppArmor where sacred
    • Configure Web site SSL for HTTPS access under Ubuntu nginx

PAC Automatic Proxy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.