如何实现IE浏览器的[局域网设置]的[自动设置]下的[使用自动脚本设置]
(在浏览器internet选项下[连接]下),给点提示信息

解决方案 »

  1.   

    不是不想回答你,是不知道你在问什么:你要给你自己的Web浏览器程序做一个配置脚本的GUI?
      

  2.   

    抱歉,现在将问题转化如下
    如何通过vc下执行一个*.asp或*.jsp文件得到相映文件所处的proxy地址和端口
    asp文件是一个URL,如http://proxy/***/*.asp文件
      

  3.   

    1、什么是代理脚本(PAC)
       一个PAC文件其实就是一个文本文件,最简单的格式就是包含一个叫FindProxyForURL的
       JScript函数,IE通过传入两个变量来调用这个函数,一个是用户浏览的地址URL全路经,
       一个是这个URL中的主机名部分(host)。这个FindProxyForURL函数有三种可能的字符串
       返回值,一是"DIRECT",就是直接连接,不通过代理;二是"PROXY proxyaddr:port",
      其中proxyaddr和port分别是代理的地址和代理的端口;三是"SOCKS socksaddr:port",
       其中socksaddr和port分别是socks代理的地址和端口,一个自动代理文件可以是多个
       选择的组合,其中用分号(;)隔开,如:
       
       function FindProxyForURL(url,host)
       {
         if (host == "www.mydomain.com")
             return "DIRECT";
     
             return "PROXY myproxy:80;
                     PROXY myotherproxy:8080; 
                     DIRECT";
       }
       
       
    2、下面是代理脚本可能用到的函数和说明:
    PAC Helper FunctionsdnsDomainIs(host, domain)              Returns true if the host is part of the
                                           specified domain, false otherwise.
     
    isInNet(hostname,                      Resolves the hostname and subnet IP,
                                           subnet mask) returns true if the
                                           hostname is within the subnet specified
                                           by the IP address and the subnet mask,
                                           false otherwise.
     
    isPlainHostName(host)                  Returns true if there are no dots in the
                                           hostname, false otherwise.
     
    isResolvable(host)                     Internet Explorer tries to resolve the
                                           hostname through DNS and returns true if
                                           successful, false otherwise.
     
    localHostOrDomainIs                    Returns true if the host matches (host,
                                           domain) the host portion of the domain,
                                           or if the host matches the host and
                                           domain portions of the domain, false
                                           otherwise. (Executed only for URLs in
                                           the local domain.)
     
    dnsDomainLevels(host)                  Returns the number of dots in the
                                           hostname.
     
    dnsResolve(host)                       Returns a string containing the IP
                                           address of the specified host.
     
    myIPAddress( )                         Returns a string containing the local
                                           machine’s IP address.
     
    shExpMatch(url, shexp)                 Returns true if the supplied URL matches
                                           the specified shell expression, false
                                           otherwise. 
     
    dateRange(parmList)                    Returns true if the current date falls
                                           within the dates specified in parmList,
                                           false otherwise. 
     
    timeRange(parmList)                    Returns true if the current time falls
                                           within the times specified in parmList,
                                           false otherwise. 
     
    weekdayRange(parmList)                 Returns true if today is within the days
                                           of the week specified in parmList, false
                                           otherwise. 3、下面是各个函数应用的例子:
      a、isPlainHostName(host),本例演示判断是否为本地主机,如http://myservername/
      的方式访问,如果是直接连接,否则使用代理
      function FindProxyForURL(url, host)
      {
        if (isPlainHostName(host))
          return "DIRECT";
        else
          return "PROXY proxy:80";
      }
      
      b、dnsDomainIs(host, "")、localHostOrDomainIs(host, ""),本例演示判断访问主机
      是否属于某个域和某个域名,如果属于.company.com域的主机名,而域名不是
      www.company.com和home.company.com的直接连接,否则使用代理访问。
      function FindProxyForURL(url, host)
      {
        if ((isPlainHostName(host) ||
           dnsDomainIs(host, ".company.com")) &&
          !localHostOrDomainIs(host, "www.company.com") &&
          !localHostOrDomainIs(host, "home.company.com"))      return "DIRECT";
        else
          return "PROXY proxy:80";
      }
      
      c、isResolvable(host),本例演示主机名能否被dns服务器解析,如果能直接访问,否
      则就通过代理访问。
      function FindProxyForURL(url, host)
      {
        if (isResolvable(host))
          return "DIRECT";
        else
          return "PROXY proxy:80";
      }
      
      d、isInNet(host, "", ""),本例演示访问IP是否在某个子网内,如果是就直接访问,
      否则就通过代理,例子演示访问清华IP段的主页不用代理。
      function FindProxyForURL(url, host)
      {
        if (isInNet(host, "166.111.0.0", "255.255.0.0"))
          return "DIRECT";
        else
          return "PROXY proxy:80";
      }
      
     e、shExpMatch(host, ""),本例演示根据主机域名来改变连接类型,本地主机、*.edu、
      *.com分别用不同的连接方式。
      function FindProxyForURL(url, host)
      {
        if (isPlainHostName(host))
          return "DIRECT";
        else if (shExpMatch(host, "*.com"))
          return "PROXY comproxy:80";
        else if (shExpMatch(host, "*.edu"))
          return "PROXY eduproxy:80";
        else
          return "PROXY proxy:80";
      }
      
     f、url.substring(),本例演示根据不同的协议来选择不同的代理,http、https、ftp、
      gopher分别使用不同的代理。
      function FindProxyForURL(url, host)
      {
          if (url.substring(0, 5) == "http:") {
            return "PROXY proxy:80";
          }
          else if (url.substring(0, 4) == "ftp:") {
            return "PROXY fproxy:80";
          }
          else if (url.substring(0, 7) == "gopher:") {
            return "PROXY gproxy";
          }
          else if (url.substring(0, 6) == "https:") {
            return "PROXY secproxy:8080";
          }
          else {
            return "DIRECT";
          }
      }
      
      g、dnsResolve(host),本例演示判断访问主机是否某个IP,如果是就使用代理,否则直
      接连接。
      unction FindProxyForURL(url, host)
      {
          if (dnsResolve(host) == "166.111.8.237") {
            return "PROXY secproxy:8080";
          }
          else {
            return "PROXY proxy:80";
          }
      }
      
      h、myIpAddress(),本例演示判断本地IP是否某个IP,如果是就使用代理,否则直接使
      用连接。
      function FindProxyForURL(url, host)
      {
          if (myIpAddress() == "166.111.8.238") { 
            return "PROXY proxy:80";
          }
          else {
            return "DIRECT";
          }
      }
      
      i、dnsDomainLevels(host),本例演示访问主机的域名级数是几级,就是域名有几个点
      如果域名中有点,就通过代理访问,否则直接连接。
      function FindProxyForURL(url, host)
      {
          if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0
            return "PROXY proxy:80";
          }
            return "DIRECT";
      }
      
      j、weekdayRange(),本例演示当前日期的范围来改变使用代理,如果是GMT时间周三
      到周六,使用代理连接,否则直接连接。
      function FindProxyForURL(url, host)
      {
        if(weekdayRange("WED", "SAT", "GMT")) 
         return "PROXY proxy:80";
        else 
         return "DIRECT";
      }
      
      k、最后一个例子是演示随机使用代理,这样可以好好利用代理服务器。
     function FindProxyForURL(url,host)
     {
          return randomProxy();
     }
     
     function randomProxy()
     {
         switch( Math.floor( Math.random() * 5 ) )
         {
             case 0:
                 return "PROXY proxy1:80";
                 break;
             case 1:
                 return "PROXY proxy2:80"; 
                 break;
             case 2:
                 return "PROXY proxy3:80";
                 break;
             case 3:
                 return "PROXY proxy4:80";
                 break;
             case 4:
                 return "PROXY proxy5:80";
                 break;
         }    
     }
      

  4.   

    例子:最后保存的扩展名为pac
    function FindProxyForURL(url, host)
    {
    if(isPlainHostName(host) || dnsDomainIs(host,".cn"))  return "DIRECT";
    else if(isInNet(host,"61.28.0.0", "255.255.240.0"))  return "DIRECT";
    else if(isInNet(host,"61.48.0.0", "255.248.0.0"))  return "DIRECT";
    else if(isInNet(host,"61.128.0.0", "255.192.0.0"))  return "DIRECT";
    .
    .
    .
    else if(isInNet(host,"192.168.100.0", "255.255.0.0"))  return "DIRECT";
    else return randomProxy();
    }//代理调度函数,代理列表加在这里
    //注意代理格式,代理之间用逗号隔开
    function randomProxy()
    {
       var proxyList = new Array(
       
       "PROXY 61.152.210.150:3128",
    .
    .
    .
      "PROXY 61.152.210.150:3128",
    //可以只写一个,建议      );//生成一个0到proxyList.length-1的随机数
       var index = Math.floor(Math.random() * proxyList.length);//   alert(proxyList[index]);
       return proxyList[index];
    //   return "DIRECT";
    }做完之后,可以放到网上,可以在本地机器上。
      

  5.   

    比如保存为C:\myproxy.pac。之后在IE或者Netscape
    的使用自动脚本的编辑框中填入file://C:/myproxy.pac,这样就可以用了。可以不停的往里面加入代理,但是最后速度可能反而会变慢
      

  6.   

    大侠tunsanty: Proxy Auto Detect Support, which is called WPAD protocol
    如何应用WPAD协议?