{"id":5748,"date":"2014-10-29T18:19:06","date_gmt":"2014-10-29T10:19:06","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=5748"},"modified":"2014-10-29T18:19:06","modified_gmt":"2014-10-29T10:19:06","slug":"%e7%94%a8%e4%bb%a3%e7%90%86%e8%87%aa%e5%8a%a8%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6pac%e7%bb%99iphone%e5%92%8cipad%e8%ae%be%e5%a4%87%e6%b7%bb%e5%8a%a0socks%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/5748.html","title":{"rendered":"\u7528\u4ee3\u7406\u81ea\u52a8\u914d\u7f6e\u6587\u4ef6PAC\u7ed9iPhone\u548ciPad\u8bbe\u5907\u6dfb\u52a0socks\u4ee3\u7406"},"content":{"rendered":"<p>iOS\u5b9e\u9645\u4e0a\u652f\u6301socks\u4ee3\u7406\u7684\uff0c\u4f46\u5728 iPhone\u548ciPad\u8bbe\u5907\u7684<\/p>\n<p>Setting -> WLAN \u4e0b\u53ea\u80fd\u770b\u5230HTTP Proxy<\/p>\n<p>HTTP Prxoy\u6709\uff13\u79cd\u6a21\u5f0f: \u5173\u95edOff\/\u624b\u52a8Manual\/\u81ea\u52a8Auto<\/p>\n<p>\u7528\u81ea\u52a8\u914d\u7f6e\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u652f\u6301socks\u4ee3\u7406<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction FindProxyForURL(url, host)\r\n{\r\n     return &quot;SOCKS proxy_host:proxy_port&quot;;\r\n}\r\n<\/pre>\n<p>\u5c06\u4e0a\u9762\u7684proxy_host\u548cproxy_port\u6362\u6210socks\u670d\u52a1\u5668\u5b9e\u9645\u7684IP\u5730\u5740\u548c\u7aef\u53e3<br \/>\n\u7136\u540e\u4fdd\u5b58\u4e3a\u3000proxy.pac<br \/>\n\u653e\u5230\u3000http:\/\/you_http_server\/proxy.pac<\/p>\n<p>\u5728 iPhone\u8bbe\u5907\u4e2d\uff0c\u6dfb\u52a0\u81ea\u52a8\u914d\u7f6e URL \u4e3a\u4e0a\u9762\u7684\u5730\u5740\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528socks\u4ee3\u7406\u4e86<\/p>\n<p>\u6269\u5c551:<br \/>\n\u5c40\u57df\u7f51\u6d41\u91cf\u4e0d\u8981\u7528\u4ee3\u7406<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction FindProxyForURL(url, host)\r\n{\r\n    if (isInNet(host, &quot;192.168.1.0&quot;, &quot;255.255.255.0&quot;))\r\n        return &quot;DIRECT&quot;;\r\n\r\n    return &quot;SOCKS proxy_host:proxy_port&quot;;\r\n}\r\n<\/pre>\n<p>\u53c2\u8003\u8d44\u6599\u3000\u3000\u4ee3\u7406\u81ea\u52a8\u914d\u7f6e\uff08Proxy Auto Config)<\/p>\n<p>\u4e00\u4e2aPAC\u6587\u4ef6\u5305\u542b\u4e00\u4e2aJavaScript\u7684\u51fd\u6570\u201dFindProxyForURL(url, host)\u201d. \u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u8bbf\u95ee\u89c4\u5219\u7684\u5b57\u7b26\u4e32\u3002\u7528\u6237\u4ee3\u7406\u6839\u636e\u8fd9\u4e9b\u89c4\u5219\u9002\u7528\u4e00\u4e2a\u7279\u5b9a\u7684\u4ee3\u7406\u5176\u6216\u8005\u76f4\u63a5\u8bbf\u95ee\u3002 \u5f53\u4e00\u4e2a\u4ee3\u7406\u670d\u52a1\u5668\u65e0\u6cd5\u54cd\u5e94\u7684\u65f6\u5019\uff0c\u591a\u4e2a\u8bbf\u95ee\u89c4\u5219\u63d0\u4f9b\u4e86\u5176\u4ed6\u7684\u540e\u5907\u8bbf\u95ee\u65b9\u6cd5\u3002 \u6d4f\u89c8\u5668\u5728\u8bbf\u95ee\u5176\u4ed6\u9875\u9762\u4ee5\u524d\uff0c\u9996\u5148\u8bbf\u95ee\u8fd9\u4e2aPAC\u6587\u4ef6\u3002PAC\u6587\u4ef6\u4e2d\u7684URL\u53ef\u80fd\u662f\u624b\u5de5\u914d\u7f6e\u7684\uff0c\u4e5f\u53ef\u80fd\u662f\u662f\u901a\u8fc7\u7f51\u9875\u7684\u7f51\u7edc\u4ee3\u7406\u81ea\u53d1\u73b0\u534f\u8bae\uff08Web Proxy Autodiscovery Protocol)\u81ea\u52a8\u914d\u7f6e\u7684\u3002<\/p>\n<p>\u4e3a\u4e86\u5b8c\u6574\u6027\u548c\u6700\u4f73\u7684\u517c\u5bb9\u6027\uff0c\u6211\u4eec\u5e94\u8be5\u8bbe\u7f6e\u7f51\u9875\u670d\u52a1\u5668(apache\u6216\u8005nginx,lighttpd\u7b49\u7b49)\u5c06\u8fd9\u4e2apac\u6587\u4ef6\u7684MIME\u7c7b\u578b\u58f0\u660e\u4e3a application\/x-ns-proxy-autoconfig \u6216\u8005 application\/x-javascript-config<br \/>\n\u5bf9\u4e8e\u73b0\u4ee3\u6d4f\u89c8\u5668\u6765\u8bf4\uff0c\u4e24\u79cdmime\u7c7b\u578b\u90fd\u6ca1\u6709\u95ee\u9898\uff0c\u3000\u4f46 application\/x-ns-proxy-autoconfig \u76f8\u5bf9 application\/x-javascript-config \u88ab\u66f4\u591a\u7684\u5ba2\u6237\u7aef\u6240\u652f\u6301,\u3000\u56e0\u4e3a\u5b83\u88ab\u5b9a\u4e49\u5728\u6700\u521d\u7684Netscape\u89c4\u8303\u91cc<\/p>\n<p>FindProxyForURL\u7684\u8fd4\u56de\u503c\uff0c\u53ef\u4ee5\u662f\u4ee5\u4e0b\uff13\u79cd\u4e4b\u4e00\uff0c\u6216\u8005\u662f\u5b83\u4eec\u7684\u7ec4\u5408<\/p>\n<p>DIRECT<br \/>\n   \u76f4\u63a5\u8fde\u63a5\uff0c\u4e0d\u4f7f\u7528\u4ee3\u7406<\/p>\n<p>PROXY host:port<br \/>\n\u3000\u3000\u3000\u4f7f\u7528\u6307\u5b9a\u7684http\u4ee3\u7406<\/p>\n<p>SOCKS host:port<br \/>\n\u3000\u3000\u3000\u4f7f\u7528\u6307\u5b9a\u7684SOCKS\u4ee3\u7406<br \/>\n\u5982\u679c\u662f\u591a\u4e2a\u7ec4\u5408\uff0c\u8981\u7528\u3000\u5206\u53f7;\u62fc\u63a5\u8d77\u6765<br \/>\n\u5e76\u4e14\uff0c\u653e\u5728\u6700\u5de6\u8fb9\u7684\u4f18\u5148\u7ea7\u6700\u9ad8\uff0c\u5982\u679c\u6700\u5de6\u8fb9\u7684\u5931\u8d25\uff0c\u4f9d\u6b21\u5f80\u53f3\u8fb9\u5c1d\u8bd5<\/p>\n<p>\u5982\u679c\u6700\u5de6\u8fb9\u7684\u4ee3\u7406\u670d\u52a1\u5668\u6302\u6389\u4e86\uff0c\u5e76\u4e14\u4f60\u5728\u53f3\u8fb9\u6ca1\u6709\u6307\u5b9aDIRECT\u9009\u9879\uff0c\u3000\u6d4f\u89c8\u5668\u5e94\u8be5\u4f1a\u95ee\u4f60<br \/>\n\u4ee3\u7406\u670d\u52a1\u5668\u6302\u4e86\uff0c\u80fd\u4e0d\u80fd\u4e34\u65f6\u5ffd\u7565\u5b83\uff0c\u76f4\u63a5\u8fde\u63a5\u7f51\u7edc?<\/p>\n<p>\u53c2\u8003\u8d44\u6599\u3000\u3000PAC Functions\u3000\uff08\u5f3a\u70c8\u63a8\u8350)<br \/>\nNavigator Proxy Auto-Config File Format (NetScape\u539f\u59cb\u89c4\u8303)<br \/>\nThe Practical Proxy PAC file guid (\u6700\u6700\u5f3a\u70c8\u63a8\u8350)<\/p>\n<p>shExpMatch(str, shexp)<br \/>\n\u7b2c1\u4e2a\u53c2\u6570str, \u5f85\u6bd4\u8f83\u7684\u4efb\u610f\u5b57\u7b26\u4e32\uff0c\u4e00\u822c\u662furl\u6216\u8005host<br \/>\n\u7b2c2\u4e2a\u53c2\u6570shexp\u662fshell\u8868\u8fbe\u5f0f,\u968f\u610f\u53ef\u4ee5\u6709*\u53f7\u901a\u914d\u7b26<\/p>\n<p>isPlainHostName(host)<br \/>\n\u5982\u679chost\u662f\u4e0d\u542b\u6709\u201d.\u201d,\u3000\u8bf4\u660e\u662f\u4e00\u4e2a\u4e3b\u673a\u540d\uff0c \u5c31\u8fd4\u56detrue;<br \/>\n\u5982\u679c\u6709\u70b9\u53f7\uff0c\u8bf4\u660e\u662f\u4e00\u4e2a\u57df\u540d, \u8fd4\u56defalse<br \/>\nhost\u662f\u4eceURL\u4e2d\u5206\u79bb\u51fa\u6765\u7684\u4e3b\u673a\u540d\uff08\u4e0d\u5305\u62ec\u7aef\u53e3\u53f7)<\/p>\n<p>isInNet(host_or_ip, pattern, mask)<br \/>\n\u8fd9\u4e2a\u51fd\u6570\u5c06\u4f1a\u8003\u5bdf\u7b2c1\u4e2a\u53c2\u6570 ip\u5730\u5740 (\u5982\u679c\u4f20\u5165\u7684\u53c2\u6570\u662f\u4e3b\u673a\u540d\uff0c\u4f1a\u88ab\u81ea\u52a8\u8f6c\u6362\u4e3aip\u5730\u5740)<br \/>\n\u770b\u5b83\u662f\u5426\u5728\u3000\u7b2c2\u4e2a\u53c2\u6570pattern \u548c\u3000\u7b2c3\u4e2a\u53c2\u6570\u3000mask \u51b3\u5b9a\u7684\u5b50\u7f51\u7edc\u8303\u56f4\u5185<\/p>\n<p>\u4f8b\u5982<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nif (isInNet(dnsResolve(host), &quot;172.16.0.0&quot;, &quot;255.240.0.0&quot;))\r\n    return &quot;DIRECT&quot;;\r\n\r\nif (isInNet(myIpAddress(), &quot;10.10.1.0&quot;, &quot;255.255.255.0&quot;))\r\n    return &quot;PROXY 10.10.5.1:8080&quot;;\r\n<\/pre>\n<p>\u5176\u4e2dmyIpAddress() \u8fd4\u56de\u3000\u6d4f\u89c8\u5668\u6240\u5728\u7684\u4e3b\u673a\u7684\u5f53\u524dIP\u5730\u5740\uff0c\u3000\u5f88\u591a\u65f6\u5019\u8fd9\u662f\u4e2a\u5c40\u57df\u7f51\u5730\u5740<\/p>\n<p>dnsResolve(host) \u5c06host\u89e3\u6790\u4e3aip\u5730\u5740<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar resolved_ip = dnsResolve(host);\r\nif (isInNet(dnsResolve(host), &quot;10.0.0.0&quot;, &quot;255.0.0.0&quot;) ||\r\n    isInNet(dnsResolve(host), &quot;172.16.0.0&quot;,  &quot;255.240.0.0&quot;) ||\r\n    isInNet(dnsResolve(host), &quot;192.168.0.0&quot;, &quot;255.255.0.0&quot;) ||\r\n    isInNet(dnsResolve(host), &quot;127.0.0.0&quot;, &quot;255.255.255.0&quot;))\r\n    return &quot;DIRECT&quot;;\r\n<\/pre>\n<p>\u8fd9\u6bb5\u5fc5\u987b\u7528\u4e0a\u554a<\/p>\n<p>dnsDomainIs(host, domain)<\/p>\n<p>if (dnsDomainIs(host, &#8220;.google.com&#8221;))<br \/>\n    return &#8220;DIRECT&#8221;;<\/p>\n<p>\u5176\u4e2dhost\u662f\u4eceURL\u5206\u79bb\u51fa\u6765\u7684\u4e3b\u673a\u540d<\/p>\n<p>localHostOrDomainIs(host, hostdom)<\/p>\n<p>if (localHostOrDomainIs(host, &#8220;www.google.com&#8221;))<br \/>\n    return &#8220;DIRECT&#8221;;<\/p>\n<p>hostdom \u662f\u3000\u57df\u540d\u5168\u79f0<br \/>\nhost \u65e2\u53ef\u4ee5\u662f\u3000\u57df\u540d\uff0c\u4e5f\u53ef\u4ee5\u662f\u3000\u7b80\u77ed\u4e3b\u673a\u540d<br \/>\n\u5982\u679c\u662f\u57df\u540d\uff0c\u5fc5\u987b\u5b8c\u5168\u540c\u3000hostdom \u5339\u914d<br \/>\n\u5982\u679c\u662f\u4e3b\u673a\u540d\uff0c\u5fc5\u987b\u540c\u3000hostdom\u7684\u4e3b\u673a\u540d\u3000\u8981\u5b8c\u5168\u5339\u914d<\/p>\n<p>isResolvable(host)<\/p>\n<p>dnsResolve(host)<\/p>\n<p>dnsDomainLevels(host)<\/p>\n<p>dnsDomainLevels(&#8220;www&#8221;)<\/p>\n<p>\u8fd4\u56de 0<\/p>\n<p>dnsDomainLevels(&#8220;www.netscape.com&#8221;)<br \/>\n\u8fd4\u56de 2<br \/>\n\u8c03\u8bd5\u662f\u4e2a\u5927\u95ee\u9898<br \/>\nPAC\u662f\u4e00\u4e2ajavascript\u811a\u672c\uff0c\u6d4f\u89c8\u5668\u5728\u6bcf\u6b21\u8bf7\u6c42\u4e00\u4e2aURL\u4e4b\u524d\uff0c\u90fd\u4f1a\u8fd0\u884c\u5b83\uff0e<br \/>\n\u4f46\u5b83\u548c\u666e\u901a\u7684js\u811a\u672c\u6709\u70b9\u4e0d\u540c<\/p>\n<p>1)\u5728PAC\u4e2d\uff0c\u6709\u4e2a\u51e0\u4e2a\u7279\u6b8a\u7684\u51fd\u6570\uff0c\u5b83\u53ea\u80fd\u5728PAC\u8fd0\u884c\uff0c\u5728\u666e\u901a\u7684js\u811a\u672c\u8fd0\u884c\u4f1a\u62a5\u544a<br \/>\n\u201cis not defined\u201d<br \/>\n\u6bd4\u5982\u3000shExpMatch<\/p>\n<p>2)PAC\u7684\u6267\u884c\uff0c\u4e5f\u4e0d\u652f\u6301js\u7684\u6240\u6709\u7279\u6027\uff0e<\/p>\n<p>3)\u5728\u4e0d\u540c\u7684\u6d4f\u89c8\u5668\u4e2d\uff0c\u5bf9pac\u811a\u672c\u7684\u6267\u884c\u6709\u7740\u4e0d\u540c\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0e<br \/>\n\u53ef\u4ee5\u7528Firefox\u7684\u9519\u8bef\u63a7\u5236\u53f0\u6765\u67e5\u770b\u9519\u8bef\u4fe1\u606f<br \/>\nIE\u4e5f\u652f\u6301alert()<br \/>\n\u5e76\u4e14\u3000pac\u6587\u4ef6\u53ef\u4ee5\u5b58\u5728\u4e8e\u672c\u5730\u6587\u4ef6\u7cfb\u7edf<br \/>\n\u7528\u3000file:\/\/\/var\/run\/x.pac \u8fd9\u6837\u7684\u8def\u5f84<br \/>\n\u800c\u4e0d\u8981\u7528\u3000http ,\u65b9\u4fbf\u8c03\u8bd5<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n function FindProxyForURL(url, host)\r\n    {\r\n        if (isPlainHostName(host) || dnsDomainIs(host, &quot;.mydomain.com&quot;))\r\n            return &quot;DIRECT&quot;;\r\n        else if (shExpMatch(host, &quot;*.com&quot;))\r\n            return &quot;PROXY proxy1.mydomain.com:8080; &quot; +\r\n                   &quot;PROXY proxy4.mydomain.com:8080&quot;;\r\n        else if (shExpMatch(host, &quot;*.edu&quot;))\r\n            return &quot;PROXY proxy2.mydomain.com:8080; &quot; +\r\n                   &quot;PROXY proxy4.mydomain.com:8080&quot;;\r\n        else\r\n            return &quot;PROXY proxy3.mydomain.com:8080; &quot; +\r\n                   &quot;PROXY proxy4.mydomain.com:8080&quot;;\r\n    }\r\n<\/pre>\n<p>\u6211\u7684\u6700\u7ec8\u7248\u672c<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction FindProxyForURL(url, host)\r\n{\r\n    url  = url.toLowerCase();\r\n    host = host.toLowerCase();\r\n\r\n    if (isInNet(dnsResolve(host), &quot;10.0.0.0&quot;, &quot;255.0.0.0&quot;) ||\r\n        isInNet(dnsResolve(host), &quot;172.16.0.0&quot;,  &quot;255.240.0.0&quot;) ||\r\n        isInNet(dnsResolve(host), &quot;192.168.0.0&quot;, &quot;255.255.0.0&quot;) ||\r\n        isInNet(dnsResolve(host), &quot;127.0.0.0&quot;, &quot;255.255.255.0&quot;))\r\n        return &quot;DIRECT&quot;;\r\n\r\n    if (shExpMatch(url,&quot;*twitter*&quot;)  ||\r\n        shExpMatch(url,&quot;*facebook*&quot;) ||\r\n        shExpMatch(url,&quot;*blogspot*&quot;) ||\r\n        shExpMatch(url,&quot;*youtube*&quot;) ||\r\n       )\r\n    {\r\n       return &quot;SOCKS 1.2.3.4:1080; DIRECT&quot;;\r\n    }\r\n}\r\n<\/pre>\n<p>Chrome\u5728Linux\u4e0b\u6ca1\u6709\u4ee3\u7406\u914d\u7f6e\u754c\u9762\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u914d\u7f6e<\/p>\n<p>&#8211;proxy-server=host:port<br \/>\n&#8211;no-proxy-server<br \/>\n&#8211;proxy-auto-detect<br \/>\n&#8211;proxy-pac-url=URL<\/p>\n<p>pac\u5c31\u7528<br \/>\n&#8211;proxy-pac-url=file:\/\/\/var\/run\/autoproxy.pac<\/p>\n<p>\u65b0\u7684\u6d4f\u89c8\u5668\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f<br \/>\n\u5982\u679c\u9700\u8981\u505a\u4e00\u4e9b\u8f83\u4e3a\u590d\u6742\u7684\u5224\u65ad\uff0c\u90a3\u53ef\u76f4\u63a5\u629b\u5f03 shExpMatch \u51fd\u6570\uff0c\u800c\u81ea\u5df1\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u522b\u7684\u5de5\u5177\u6765\u8fdb\u884c\u5224\u65ad\uff0c\u5982\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n var regexpr = \/&#x5B;a-zA-Z]{4}.microsoft.com\/;\r\n    if(regexpr.test(host))\r\n        return &quot;PROXY w3proxy:8080; DIRECT&quot;;\r\n\r\n\u8c03\u8bd5\uff0c\u4f7f\u7528alert,\u5728IE\u4e0a\u6ca1\u95ee\u9898\r\n\r\n&#x5B;sourcecode language=&quot;javascript&quot;]\r\nfunction isMatchProxy(url, pattern) {\r\n    try {\r\n        return new RegExp(pattern.replace('.', '.')).test(url);\r\n    } catch (e) {\r\n        return false;\r\n    }\r\n}\r\n\r\nfunction FindProxyForURL(url, host) {\r\n    debugPAC =&quot;PAC Debug Informationn&quot;;\r\n    debugPAC +=&quot;-----------------------------------n&quot;;\r\n    debugPAC +=&quot;Machine IP: &quot; + myIpAddress() + &quot;n&quot;;\r\n    debugPAC +=&quot;Hostname: &quot; + host + &quot;n&quot;;\r\n    if (isResolvable(host)) {\r\n        resolvableHost = &quot;True&quot;\r\n    } else {\r\n        resolvableHost = &quot;False&quot;\r\n    };\r\n    debugPAC += &quot;Host Resolvable: &quot; + resolvableHost + &quot;n&quot;;\r\n    debugPAC += &quot;Hostname IP: &quot; + dnsResolve(host) + &quot;n&quot;;\r\n    if (isPlainHostName(host)) {\r\n        plainHost = &quot;True&quot;\r\n    } else {\r\n        plainHost = &quot;False&quot;\r\n    };\r\n    debugPAC += &quot;Plain Hostname: &quot; + plainHost + &quot;n&quot;;\r\n    debugPAC += &quot;Domain Levels: &quot; + dnsDomainLevels(host) + &quot;n&quot;;\r\n    debugPAC += &quot;URL: &quot; + url + &quot;n&quot;;\r\n    alert(debugPAC);\r\n    var Proxy = 'SOCKS 1.2.3.4:9625; DIRECT';\r\n\r\n    var list = &#x5B;\r\n        't.co',\r\n        'twitter.com',\r\n        'twimg.com',\r\n        'posterous.com',\r\n        'tinypic.com',\r\n        'twitpic.com',\r\n        'bitly.com',\r\n        'yfrog.com',\r\n        'youtube.com',\r\n        'facebook.com',\r\n        'appspot.com',\r\n        'dropbox.com',\r\n        'flickr.com',\r\n        'youtube.com',\r\n        'ytimg.com',\r\n        'plus.google.com',\r\n        'ggpht.com',\r\n        'talkgadget.google.com',\r\n        'picasaweb.google.com',\r\n        'googleusercontent.com',\r\n        'hzmangel.info',\r\n        'slideshare.net',\r\n        'code.google.com',\r\n        'golang.org',\r\n        'vimeo.com',\r\n        'wordpress.com',\r\n        'dxtl.net',\r\n        '123cha.com'\r\n    ];\r\n\r\n    for(var i=0, l=list.length; i&lt;l; i++) {\r\n        if (isMatchProxy(url, list&#x5B;i])) {\r\n            alert(&quot;Match&quot;);\r\n            return Proxy;\r\n        }\r\n    }\r\n\r\n    alert(&quot;direct&quot;);\r\n    return 'DIRECT';\r\n}\r\n<\/pre>\n<p>\u5728PAC\u4e2d\uff0cFirefox\u548cInternet Explore\u90fd\u652f\u6301alert\u8bed\u53e5\uff0cIE\u7684\u8868\u73b0\u540c\u666e\u901ajs\u4e00\u6837<br \/>\nFirefox\u662f\u5728\u3000\u3000\u201d\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\u201d\uff08Ctrl+Shift+J\u5feb\u6377\u952e\u8c03\u51fa\u6765) JS\u6807\u7b7e\u3000\u91cc\u663e\u793a\u51fa\u6765<\/p>\n<p>\u2014<br \/>\n[21:32:29.568] PAC-alert: PAC Debug Information<br \/>\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<br \/>\nMachine IP: 192.168.1.99<br \/>\nHostname: zhiwei.li<br \/>\nHost Resolvable: True<br \/>\nHostname IP: 199.188.204.95<br \/>\nPlain Hostname: False<br \/>\nDomain Levels: 1<br \/>\nURL: http:\/\/zhiwei.li\/<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u53e6\u5916\u4e00\u4e2a\u4f8b\u5b50<\/p>\n<p>\u7531\u4e8e.pac \u6587\u4ef6\u652f\u6301\u6574\u4e2a JavaScript \u8bed\u8a00\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u8c61\uff0c\u5e76\u6d4b\u8bd5\u65b9\u6cd5\u6765\u6d4b\u8bd5\u5bf9\u7167\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u4e32\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u4f7f\u7528.pac \u6587\u4ef6\u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u8c61\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction FindProxyForURL(url, host)\r\n{\r\n    \/\/ For instance, if the server has 4 alphabetic characters,\r\n    \/\/ such as &quot;MSDN&quot;, route it through a specific proxy:\r\n   var regexpr = \/&#x5B;a-zA-Z]{4}.microsoft.com\/;\r\n   if(regexpr.test(host))\r\n      return &quot;PROXY w3proxy:8080; DIRECT&quot;;\r\n\r\n   \/\/ Or else connect directly:\r\n   return &quot;DIRECT&quot;;\r\n}\r\n<\/pre>\n<p>http:\/\/technet.microsoft.com\/en-us\/library\/dd361950.aspx (\u5fae\u8f6f\u7ed9\u7684\u4f8b\u5b50)<\/p>\n<p>\u9a8c\u8bc1\u5de5\u5177<\/p>\n<p>https:\/\/code.google.com\/p\/pacparser\/\u3000\u3000\u3000\uff08\u652f\u6301Python\u548cC)<\/p>\n<p>http:\/\/www.jslint.com\/ (\u9a8c\u8bc1\u4f60\u7684js\u8bed\u6cd5)<\/p>\n<p>Debian Jessie\u4e2d\u7684IceWeasel 24.1.0 \u5bf9 PAC\u7684\u652f\u6301\u6709\u95ee\u9898\uff0c<br \/>\nWindows\u7248\u672c\u7684Firefox 26.0\u5c31\u80fd\u5f88\u597d\u7684\u652f\u6301<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff0c\u5b89\u88c5\u3000\u6269\u70b8\u3000\u3000foxyproxy<br \/>\nxul-ext-foxyproxy-standard \u6216\u8005\u4ecemozilla addons\u4e0b\u8f7d<\/p>\n<p>SOCKS SOCKS4 SOCKS5\u7684\u95ee\u9898<\/p>\n<p>\u201cSOCKS host:port\u201d<br \/>\n\u6709\u7684\u6d4f\u89c8\u5668\u4f7f\u7528SOCKS4\u534f\u8bae\uff0c\u4e5f\u652f\u6301DNS \u89e3\u6790\u3000\u3000\uff08IceWeasel \u7684\u4ee3\u7406\u7ba1\u7406\uff0c\u5c31\u662f\u8fd9\u4e2a\u505a\u6cd5\uff0c\u3000\u4f46\u662fSOCKS4\u5b9e\u9645\u4e0a\u662f\u4e0d\u652f\u6301 DNS\u89e3\u6790\u7684\uff0csocks\uff15\u670d\u52a1\u770b\u5230\u534f\u8bae\u7248\u672c\u662f4,\u3000dns\u8bf7\u6c42\u662f\u672a\u77e5\u7684\uff0c\u5c31\u4f1a\u76f4\u63a5\u5173\u6389\u8fde\u63a5<br \/>\n\u6240\u4ee5\uff0c\u3000\u4f60\u5728 firefox\u91cc\u9009\u4e2dsocks4\u534f\u8bae\uff0c\u5c31\u4e0d\u8981\u3000\u8ba9\u3000extensions.foxyproxy.socks_remote_dns\u3000\u8fd9\u4e2a\u9009\u9879\u4e3atrue<br \/>\n\u4f46\u662f\uff0c\u5982\u679c\u4e0d\u505a\u8fdc\u7a0bdns\u7684\u8bdd\uff0c\u4f1f\/\u5927\u7684-\u57ce\uff3f\u5899\u3000\u4f1a\u6c61\u67d3DNS)<\/p>\n<p>\u6709\u7684\u6d4f\u89c8\u5668\u4f7f\u7528SOCKS4\u534f\u8bae\uff0c\u4f46\u4e0d\u652f\u6301 DNS\u89e3\u6790<br \/>\n\u6709\u7684\u6d4f\u89c8\u5668\u76f4\u63a5\u4f7f\u7528SOCKS5\u534f\u8bae\uff0c\u5f53\u7136\u5c31\u652f\u6301 DNS\u89e3\u6790\u4e86 (foxyProxy\u6269\u5c55\uff0c\u770b\u5230 SOCKS\uff0c\u5c31\u76f4\u63a5\u7528SOCKS5\u4e86,\u76f8\u5f53\u806a\u660e)<\/p>\n<p>\u201cSOCKS5 host:port\u201d \u3000\u3000\u660e\u786e\u8bf4\u660e\u8981\u7528 SOCKS5 \u4ee3\u7406<br \/>\n\u636e\u8bf4\u3000Safari (OSX, iOS)\u53ea\u8ba4\u8bc6SOCKS,\u867d\u7136\u5b83\u9ed8\u8ba4\u4e5f\u662f\u4f7f\u7528SOCKS5\u534f\u8bae<\/p>\n<p>SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT<br \/>\n\u8fd9\u79cd\u5199\u6cd5\u53ef\u4ee5\u517c\u5bb9\u7edd\u5927\u6570\u6d4f\u89c8\u5668<br \/>\n\u5bf9\u4e8e\u4e0d\u8ba4\u8bc6\u7684SOCKS5,\u4e22\u6389\uff0c\u8ba4\u8bc6\u7684SOCKS\u76f4\u63a5\u7528<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS\u5b9e\u9645\u4e0a\u652f\u6301socks\u4ee3\u7406\u7684\uff0c\u4f46\u5728 iPhone\u548ciPad\u8bbe\u5907\u7684 Setting -> WLAN \u4e0b\u53ea\u80fd\u770b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5748","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=5748"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5748\/revisions"}],"predecessor-version":[{"id":5749,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5748\/revisions\/5749"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=5748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=5748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=5748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}