home  -  about me  -  2009  -  2008  -  2007  -  2006  -  2005  -  nerd's substance  -  itch  -  shuffle  -  what
Mac  -  Photos
  Livid's Paranoid - nerd's substance - PAC & SSH   
PAC & SSH
之前我一直在用 FoxyProxy 来配置 Firefox 的代理功能, FoxyProxy 很强大, 但是有一些问题很麻烦: FoxyProxy 的配置貌似没办法在多台机器之间转移, 太多的鼠标操作(这或许不算是个问题, 但是如果能够通过编辑一个文件来实现同样的功能的话会好很多, 因为纯文本文件很容易被编辑和复制, 并且也很容易放进版本控制系统).

最近发现了 PAC 文件可以完整地取代 FoxyProxy 而且有非常多的优点. PAC 是 proxy auto-config 的缩写, 实质是一段纯文本的 JavaScript, 实现了一个叫做 FindProxyForURL(url, host) 的函数, 这个函数的返回值就是代理服务器的信息. 比如下面这个是我目前在用的 PAC 文件的内容:

function FindProxyForURL(url, host) { if (shExpMatch(url, "*.wikipedia.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.apple.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.tumblr.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.soup.io/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.pandora.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.last.fm/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.adobe.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.photoshop.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.google.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.googlecode.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.blogspot.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.appspot.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.acer.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.demonoid.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.alexa.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.wikimedia.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.flickr.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.yahoo.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.zend.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.aptana.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.uncyclopedia.tw/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "uncyclopedia.tw/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.uncyc.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.youtube.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.webarchive.org/*")) { return "SOCKS 127.0.0.1:7777"; } return "DIRECT"; }

这个函数的语法可以看 Netscape 网站上的文档, 你可以在 return 处使用 PROXY 或者 SOCKS 来选择 http 或者 socks 协议的代理, DIRECT 的意思即不使用代理直接连接. PAC 文件被几乎所有的主流浏览器支持, Mac OS X 操作系统的 Network 控制面板中也有对 PAC 文件的支持.

在我本地的配置中, 我是用 ssh 连接到一台美国的高速服务器, 并打开一个 SOCKS 通道的方式实现加密的代理通讯. 你可以在 *nix 操作系统的命令行中运行:

ssh -D 7777 username@remotehost.com

就可以在本地的 7777 端口打开一个 SOCKS 代理. 这种方式除了可以实现无障碍的访问之外, 如果代理服务器足够快, 那么甚至可以用来加速访问, 比如我就用这样的方式加速在 Apple 的网站上看新电影的预告片.
之前我一直在用 FoxyProxy 来配置 Firefox 的代理功能, FoxyProxy 很强大, 但是有一些问题很麻烦: FoxyProxy 的配置貌似没办法在多台机器之间转移, 太多的鼠标操作(这或许不算是个问题, 但是如果能够通过编辑一个文件来实现同样的功能的话会好很多, 因为纯文本文件很容易被编辑和复制, 并且也很容易放进版本控制系统).

最近发现了 PAC 文件可以完整地取代 FoxyProxy 而且有非常多的优点. PAC 是 proxy auto-config 的缩写, 实质是一段纯文本的 JavaScript, 实现了一个叫做 FindProxyForURL(url, host) 的函数, 这个函数的返回值就是代理服务器的信息. 比如下面这个是我目前在用的 PAC 文件的内容:

function FindProxyForURL(url, host) { if (shExpMatch(url, "*.wikipedia.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.apple.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.tumblr.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.soup.io/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.pandora.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.last.fm/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.adobe.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.photoshop.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.google.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.googlecode.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.blogspot.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.appspot.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.acer.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.demonoid.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.alexa.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.wikimedia.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.flickr.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.yahoo.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.zend.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.aptana.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.uncyclopedia.tw/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "uncyclopedia.tw/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.uncyc.org/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.youtube.com/*")) { return "SOCKS 127.0.0.1:7777"; } if (shExpMatch(url, "*.webarchive.org/*")) { return "SOCKS 127.0.0.1:7777"; } return "DIRECT"; }

这个函数的语法可以看 Netscape 网站上的文档, 你可以在 return 处使用 PROXY 或者 SOCKS 来选择 http 或者 socks 协议的代理, DIRECT 的意思即不使用代理直接连接. PAC 文件被几乎所有的主流浏览器支持, Mac OS X 操作系统的 Network 控制面板中也有对 PAC 文件的支持.

在我本地的配置中, 我是用 ssh 连接到一台美国的高速服务器, 并打开一个 SOCKS 通道的方式实现加密的代理通讯. 你可以在 *nix 操作系统的命令行中运行:

ssh -D 7777 username@remotehost.com

就可以在本地的 7777 端口打开一个 SOCKS 代理. 这种方式除了可以实现无障碍的访问之外, 如果代理服务器足够快, 那么甚至可以用来加速访问, 比如我就用这样的方式加速在 Apple 的网站上看新电影的预告片.
by ~Livid - [ nerd's substance ] - 2008-05-21 03:06:17 - 2008-05-21 02:49:22 - 16592+15581
Sponsor
M6
这里的评论功能已经关闭,如果你觉得这不公平,那么请到 V2EX 发表你的看法 > V2EX.com
Look Around...
Maybe you will be interested on these?
Mementos: Do you remember
  
  
    Mac.6.cn footbig.com go.6.cn
    RSS 2.0 XML Feed Valid RSS 2.0 XML Feed Get Firefox!
    PHP Powered!  Subscribe with Bloglines!
    Livid: Livid Von Torvalds
    This is the personal site of Xin Livid Liu. It started since 2005.

    You can view my more detailed profile on LinkedIn and Facebook. Or follow me on Twitter.

    This site is up for 2062 days, 930 articles have been viewed for 5791740+3686965 times, average 6227.68 times per article, regularly there are 3.15 new articles per week.
    Buddies: Dear
    Links: Outside the Window
    vik|coon - 38.107.191.116 - CCBot/1.0 (+http://www.commoncrawl.org/bot.html)

    vik|engine - This installation on Apache has got 10098316 overall meaningful hits.

    Project VIK - $Id: lividecay.php 8 2007-02-03 22:47:45Z livid $
      All my works, except where otherwise noted, are licensed under a Creative Commons License

      Technorati Profile

      You will engage in a profitable business activity.