﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-每日一得-随笔分类-network</title><link>http://www.blogjava.net/alex/category/13156.html</link><description>不求多得,只求一得
about java,hibernate,spring,design,database,linux,etc.
&lt;br/&gt;&lt;br/&gt;
最近关心的内容关键字:web快速开发方案，建模,workshop studio,Ajax
</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 14:56:04 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 14:56:04 GMT</pubDate><ttl>60</ttl><item><title>[转]自动代理脚本的函数说明与应用</title><link>http://www.blogjava.net/alex/archive/2006/07/21/59418.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Fri, 21 Jul 2006 06:57:00 GMT</pubDate><guid>http://www.blogjava.net/alex/archive/2006/07/21/59418.html</guid><wfw:comment>http://www.blogjava.net/alex/comments/59418.html</wfw:comment><comments>http://www.blogjava.net/alex/archive/2006/07/21/59418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alex/comments/commentRss/59418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alex/services/trackbacks/59418.html</trackback:ping><description><![CDATA[
		<font class="content">key words:自动脚本 代理脚本 代理 冲出窗子 <br /><br />
本文献给那些对自动代理脚本有兴趣、想自己写的朋友。<br /><br />
1、什么是代理脚本(PAC)<br />
 一个PAC文件其实就是一个文本文件，最简单的格式就是包含一个叫FindProxyForURL的<br />
 JScript函数，IE通过传入两个变量来调用这个函数，一个是用户浏览的地址URL全路经，<br />
 一个是这个URL中的主机名部分(host)。这个FindProxyForURL函数有三种可能的字符串<br />
 返回值，一是"DIRECT"，就是直接连接，不通过代理；二是"PROXY proxyaddr:port"，<br />
 其中proxyaddr和port分别是代理的地址和代理的端口；三是"SOCKS socksaddr:port"，<br />
 其中socksaddr和port分别是socks代理的地址和端口，一个自动代理文件可以是多个<br />
 选择的组合，其中用分号(;)隔开，如：<br />
   <br />
   function FindProxyForURL(url,host)<br />
   {<br />
     if (host == "www.mydomain.com")<br />
         return "DIRECT";<br />
 <br />
         return "PROXY myproxy:80;<br />
                 PROXY myotherproxy:8080; <br />
                 DIRECT";<br />
   }<br />
   <br />
   <br />
2、下面是代理脚本可能用到的函数和说明：<br />
PAC Helper Functions<br /><br />
dnsDomainIs(host, domain)              Returns true if the host is part of the<br />
                                       specified domain, false otherwise.<br />
 <br />
isInNet(hostname,                      Resolves the hostname and subnet IP,<br />
                                       subnet mask) returns true if the<br />
                                       hostname is within the subnet specified<br />
                                       by the IP address and the subnet mask,<br />
                                       false otherwise.<br />
 <br />
isPlainHostName(host)                  Returns true if there are no dots in the<br />
                                       hostname, false otherwise.<br />
 <br />
isResolvable(host)                     Internet Explorer tries to resolve the<br />
                                       hostname through DNS and returns true if<br />
                                       successful, false otherwise.<br />
 <br />
localHostOrDomainIs                    Returns true if the host matches (host,<br />
                                       domain) the host portion of the domain,<br />
                                       or if the host matches the host and<br />
                                       domain portions of the domain, false<br />
                                       otherwise. (Executed only for URLs in<br />
                                       the local domain.)<br />
 <br />
dnsDomainLevels(host)                  Returns the number of dots in the<br />
                                       hostname.<br />
 <br />
dnsResolve(host)                       Returns a string containing the IP<br />
                                       address of the specified host.<br />
 <br />
myIPAddress( )                         Returns a string containing the local<br />
                                       machine’s IP address.<br />
 <br />
shExpMatch(url, shexp)                 Returns true if the supplied URL matches<br />
                                       the specified shell expression, false<br />
                                       otherwise. <br />
 <br />
dateRange(parmList)                    Returns true if the current date falls<br />
                                       within the dates specified in parmList,<br />
                                       false otherwise. <br />
 <br />
timeRange(parmList)                    Returns true if the current time falls<br />
                                       within the times specified in parmList,<br />
                                       false otherwise. <br />
 <br />
weekdayRange(parmList)                 Returns true if today is within the days<br />
                                       of the week specified in parmList, false<br />
                                       otherwise. <br /><br />
3、下面是各个函数应用的例子：<br />
  a、isPlainHostName(host)，本例演示判断是否为本地主机，如http://myservername/<br />
  的方式访问，如果是直接连接，否则使用代理<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if (isPlainHostName(host))<br />
      return "DIRECT";<br />
    else<br />
      return "PROXY proxy:80";<br />
  }<br />
  <br />
  b、dnsDomainIs(host, "")、localHostOrDomainIs(host, "")，本例演示判断访问主机<br />
  是否属于某个域和某个域名，如果属于.company.com域的主机名，而域名不是<br />
  www.company.com和home.company.com的直接连接，否则使用代理访问。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if ((isPlainHostName(host) ||<br />
       dnsDomainIs(host, ".company.com")) &amp;&amp;<br />
      !localHostOrDomainIs(host, "www.company.com") &amp;&amp;<br />
      !localHostOrDomainIs(host, "home.company.com"))<br /><br />
      return "DIRECT";<br />
    else<br />
      return "PROXY proxy:80";<br />
  }<br />
  <br />
  c、isResolvable(host)，本例演示主机名能否被dns服务器解析，如果能直接访问，否<br />
  则就通过代理访问。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if (isResolvable(host))<br />
      return "DIRECT";<br />
    else<br />
      return "PROXY proxy:80";<br />
  }<br />
  <br />
  d、isInNet(host, "", "")，本例演示访问IP是否在某个子网内，如果是就直接访问，<br />
  否则就通过代理，例子演示访问清华IP段的主页不用代理。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if (isInNet(host, "166.111.0.0", "255.255.0.0"))<br />
      return "DIRECT";<br />
    else<br />
      return "PROXY proxy:80";<br />
  }<br />
  <br />
 e、shExpMatch(host, "")，本例演示根据主机域名来改变连接类型，本地主机、*.edu、<br />
  *.com分别用不同的连接方式。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if (isPlainHostName(host))<br />
      return "DIRECT";<br />
    else if (shExpMatch(host, "*.com"))<br />
      return "PROXY comproxy:80";<br />
    else if (shExpMatch(host, "*.edu"))<br />
      return "PROXY eduproxy:80";<br />
    else<br />
      return "PROXY proxy:80";<br />
  }<br />
  <br />
 f、url.substring()，本例演示根据不同的协议来选择不同的代理，http、https、ftp、<br />
  gopher分别使用不同的代理。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
      if (url.substring(0, 5) == "http:") {<br />
        return "PROXY proxy:80";<br />
      }<br />
      else if (url.substring(0, 4) == "ftp:") {<br />
        return "PROXY fproxy:80";<br />
      }<br />
      else if (url.substring(0, 7) == "gopher:") {<br />
        return "PROXY gproxy";<br />
      }<br />
      else if (url.substring(0, 6) == "https:") {<br />
        return "PROXY secproxy:8080";<br />
      }<br />
      else {<br />
        return "DIRECT";<br />
      }<br />
  }<br />
  <br />
  g、dnsResolve(host)，本例演示判断访问主机是否某个IP，如果是就使用代理，否则直<br />
  接连接。<br />
  unction FindProxyForURL(url, host)<br />
  {<br />
      if (dnsResolve(host) == "166.111.8.237") {<br />
        return "PROXY secproxy:8080";<br />
      }<br />
      else {<br />
        return "PROXY proxy:80";<br />
      }<br />
  }<br />
  <br />
  h、myIpAddress()，本例演示判断本地IP是否某个IP，如果是就使用代理，否则直接使<br />
  用连接。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
      if (myIpAddress() == "166.111.8.238") { <br />
        return "PROXY proxy:80";<br />
      }<br />
      else {<br />
        return "DIRECT";<br />
      }<br />
  }<br />
  <br />
  i、dnsDomainLevels(host)，本例演示访问主机的域名级数是几级，就是域名有几个点<br />
  如果域名中有点，就通过代理访问，否则直接连接。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
      if (dnsDomainLevels(host) &gt; 0) { // if number of dots in host &gt; 0<br />
        return "PROXY proxy:80";<br />
      }<br />
        return "DIRECT";<br />
  }<br />
  <br />
  j、weekdayRange()，本例演示当前日期的范围来改变使用代理，如果是GMT时间周三<br />
  到周六，使用代理连接，否则直接连接。<br />
  function FindProxyForURL(url, host)<br />
  {<br />
    if(weekdayRange("WED", "SAT", "GMT")) <br />
     return "PROXY proxy:80";<br />
    else <br />
     return "DIRECT";<br />
  }<br />
  <br />
  k、最后一个例子是演示随机使用代理，这样可以好好利用代理服务器。<br />
 function FindProxyForURL(url,host)<br />
 {<br />
      return randomProxy();<br />
 }<br />
 <br />
 function randomProxy()<br />
 {<br />
     switch( Math.floor( Math.random() * 5 ) )<br />
     {<br />
         case 0:<br />
             return "PROXY proxy1:80";<br />
             break;<br />
         case 1:<br />
             return "PROXY proxy2:80"; <br />
             break;<br />
         case 2:<br />
             return "PROXY proxy3:80";<br />
             break;<br />
         case 3:<br />
             return "PROXY proxy4:80";<br />
             break;<br />
         case 4:<br />
             return "PROXY proxy5:80";<br />
             break;<br />
     }    <br />
 }<br />
 <br />
利用上面的函数和例子说明，大家就可以写出比较复杂有效的自动代理脚本。</font>
<img src ="http://www.blogjava.net/alex/aggbug/59418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alex/" target="_blank">Alex</a> 2006-07-21 14:57 <a href="http://www.blogjava.net/alex/archive/2006/07/21/59418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装匿名代理绕过GFW</title><link>http://www.blogjava.net/alex/archive/2006/07/17/58525.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Mon, 17 Jul 2006 03:01:00 GMT</pubDate><guid>http://www.blogjava.net/alex/archive/2006/07/17/58525.html</guid><wfw:comment>http://www.blogjava.net/alex/comments/58525.html</wfw:comment><comments>http://www.blogjava.net/alex/archive/2006/07/17/58525.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alex/comments/commentRss/58525.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alex/services/trackbacks/58525.html</trackback:ping><description><![CDATA[
		<h2>Windows</h2>
		<ul>
				<li>下载并安装 Tor &amp; Privoxy<br /><a href="http://www.vidalia-project.net/dist/vidalia-bundle-0.1.1.21-0.0.5.exe">http://www.vidalia-project.net/dist/vidalia-bundle-0.1.1.21-0.0.5.exe</a><br />
安装完之后，在localhost:8118有http代理（privoxy提供），localhost:9050有socks5代理(tor提供)<br />
如果这时候可以配置Firefox使用8118和9050这两个端口，那就所有的Internet访问都将通过tor访问，会很慢。所以这种方式不推荐，要自己编辑一下代理配置脚本<br /><img src="http://tor.eff.org/img/screenshot-win32-firefox-proxies.jpg" alt="Proxy settings in Firefox" height="505" width="525" /></li>
				<li>编辑proxy.pac<br />
可以在某个地方创建代理配置脚本, 比如说c:\proxy.pac, 下面是我用的内容, 可以上一些比较常用的网站,
比如wikipedia和google网页快照. 如果查询google也经常有问题, 可以把第一条 nosite.google.com 改成
.google.com　记得google.com前面有个点, 这样所有访问google的请求都会通过代理，不过做好心理准备，会很慢
<pre>function FindProxyForURL(url, host)<br />{<br />url = url.toLowerCase();<br />host = host.toLowerCase();<br /><br />if(dnsDomainIs(host,"nosite.google.com")) return "PROXY localhost:8118";<br />else if(dnsDomainIs(host,".blogspot.com")) return "PROXY localhost:8118";<br />else if(dnsDomainIs(host,".wordpress.com")) return "PROXY localhost:8118";<br />else if(dnsDomainIs(host,"wikipedia.org")) return "PROXY localhost:8118";<br />else if(shExpMatch(url,"*q=cache:*"))  return "PROXY localhost:8118";<br />else return "DIRECT";<br />}<br /></pre></li>
				<li>配置IE使用代理配置脚本<br />
上面那个Firefox配置界面中，选择Aotumatic proxy configuration URL, 填入
<pre>file://c:/proxy.pac</pre><p>IE的配置类似．每次重新修改proxy.pac，都应该到上面的界面Reload代理配置脚本(比较讨厌，好在这个文件修改次数不会很多)
</p></li>
		</ul>
		<h2>Debian Linux</h2>
		<p>这里主要讲Debian下的安装配置，其他版本的Linux可以参考tor的<a href="http://tor.eff.org/docs/tor-doc-unix.html.en">官方说明</a></p>
		<ul>
				<li>安装 tor privoxy</li>
				<pre> apt-get install tor privoxy<br /></pre>
				<li>配置privoxy</li>
				<p>Debian下面的privoxy需要额外的配置，因为privoxy需要使用tor提供的9050 socks5端口．具体是配置/etc/privoxy/config，加一行
</p>
				<pre>forward-socks4a / localhost:9050 .<br /></pre>
				<p>不要漏掉最后的点．然后重起一下privoxy
</p>
				<pre>/etc/init.d/tor restart<br /></pre>
				<li>如果使用Firefox，剩下的配置可以参考Windows下面的配置方法</li>
		</ul>
		<h2>参考</h2>
		<p>
				<a href="http://www.linuxsir.org/bbs/showthread.php?t=232436">http://www.linuxsir.org/bbs/showthread.php?t=232436</a>
				<br />
				<a href="http://tor.eff.org/docs/tor-doc-win32.html.en">http://tor.eff.org/docs/tor-doc-win32.html.en</a>
		</p>
		<p>Technorati Tags: <a href="http://technorati.com/tag/GFW" rel="tag">GFW</a>, <a href="http://technorati.com/tag/tor" rel="tag">tor</a>, <a href="http://technorati.com/tag/%E4%BB%A3%E7%90%86" rel="tag">代理</a></p>
<img src ="http://www.blogjava.net/alex/aggbug/58525.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alex/" target="_blank">Alex</a> 2006-07-17 11:01 <a href="http://www.blogjava.net/alex/archive/2006/07/17/58525.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>