您现在的位置:首页 > 教案怎么写 > 正文

pac自动代理脚本地址_创建pac自动代理文件_pac代理地址

2019-08-24 11:01 网络整理 教案网

创建pac自动代理文件_pac自动代理脚本地址_pac代理地址

1、什么是代理脚本(PAC)

一个PAC文件其实就是一个文本文件,最简单的格式就是包含一个叫FindProxyForURL的

JScript函数,IE通过传入两个变量来调用这个函数,一个是用户浏览的地址URL全路经,

一个是这个URL中的主机名部分(host)。这个FindProxyForURL函数有三种可能的字符串

返回值,一是"DIRECT",就是直接连接,不通过代理;二是"PROXYproxyaddr:port",

其中proxyaddr和port分别是代理的地址和代理的端口;三是"SOCKSsocksaddr:port"pac自动代理脚本地址

其中socksaddr和port分别是socks代理的地址和端口,一个自动代理文件可以是多个

选择的组合,其中用分号(;)隔开,如:

functionFindProxyForURL(url,host)

{

if(host=="www.mydomain.com")

return"DIRECT";

return"PROXYmyproxy:80;

PROXYmyotherproxy:8080;

DIRECT";

}

2、下面是代理脚本可能用到的函数和说明:

swoole_async_dns_lookup($domain, function($host, $ip) use($remote, $port, $server, $fd) { 。host: 。host=

specifieddomain,falseotherwise.

isInNet(hostname,ResolvesthehostnameandsubnetIP,

subnetmask)returnstrueifthe

hostnameiswithinthesubnetspecified

bytheIPaddressandthesubnetmask,

falseotherwise.

isPlainHostName(host)Returnstrueiftherearenodotsinthe

hostname,falseotherwise.

isResolvable(host)InternetExplorertriestoresolvethe

hostnamethroughDNSandreturnstrueif

successful,falseotherwise.

localHostOrDomainIsReturnstrueifthehostmatches(host,

domain)thehostportionofthedomain,

orifthehostmatchesthehostand

domainportionsofthedomain,false

otherwise.(ExecutedonlyforURLsin

thelocaldomain.)

dnsDomainLevels(host)Returnsthenumberofdotsinthe

hostname.

dnsResolve(host)ReturnsastringcontainingtheIP

addressofthespecifiedhost.

myIPAddress()Returnsastringcontainingthelocal

machine’sIPaddress.

shExpMatch(url,shexp)ReturnstrueifthesuppliedURLmatches

thespecifiedshellexpression,false

otherwise.

a4faa1e6cc3cc3c222e7a4d854463b73

php文件中的onview函数 $return = call_user_func(uc_api_func, 'pm', 'view', array('uid'=>$uid, 'pmid'=>$pmid, 'touid'=>$touid, 'daterange'=>$daterange, 'page' => $page, 'pagesize' => $pagesize, 'type'=>$type, 'isplid'=>$isplid))。multiply多表单型,daterange时间范围。 where ord.orderdate >= daterange.startdate && ord.orderdate < daterange.enddate 。

withinthedatesspecifiedinparmList,

falseotherwise.

timeRange(parmList)Returnstrueifthecurrenttimefalls

withinthetimesspecifiedinparmList,

falseotherwise.

weekdayRange(parmList)Returnstrueiftodayiswithinthedays

oftheweekspecifiedinparmList,false

otherwise.3、下面是各个函数应用的例子:

a、isPlainHostName(host),本例演示判断是否为本地主机,如

的方式访问,如果是直接连接,否则使用代理

functionFindProxyForURL(url,host)

{

if(isPlainHostName(host))

return"DIRECT";

else

return"PROXYproxy:80";

}

b、dnsDomainIs(host,"")、localHostOrDomainIs(host,""),本例演示判断访问主机

是否属于某个域和某个域名,如果属于.company.com域的主机名,而域名不是

和home.company.com的直接连接,否则使用代理访问。

functionFindProxyForURL(url,host)

{

if((isPlainHostName(host)||

dnsDomainIs(host,".company.com"))&&

!localHostOrDomainIs(host,"www.company.com")&&

!localHostOrDomainIs(host,"home.company.com"))return"DIRECT";

else

return"PROXYproxy:80";

}

c、isResolvable(host),本例演示主机名能否被dns服务器解析,如果能直接访问,否

则就通过代理访问。

functionFindProxyForURL(url,host)

{

if(isResolvable(host))

return"DIRECT";

else

return"PROXYproxy:80";

}

d、isInNet(host,"",""),本例演示访问IP是否在某个子网内,如果是就直接访问,

否则就通过代理,例子演示访问清华IP段的主页不用代理。

functionFindProxyForURL(url,host)

{

if(isInNet(host,"166.111.0.0","255.255.0.0"))

pac代理地址_创建pac自动代理文件_pac自动代理脚本地址

return"DIRECT";

else

return"PROXYproxy:80";

}

4、但是通过这种方式获得的ip地址是动态的,那么会给用户访问时造成困扰,ip总是会改变,可通过域名解析来绑定动态ip,正常绑定后使用域名通过客户端软件或者ie直接输入域名的方式来访问。「注」 主机a使用远程桌面连接主机b后,便可对主机b进行任何操作,此处不做演示,同学可以自行实验。当计算机对域名访问时并不是每次访问都需要向dns服务器寻求帮助的,一般来说当解析工作完 成一次后,该解析条目会保存在计算机的dns缓存列表中,如果这时dns解析出现更改变动的话,由于dns缓存列表信息没有改变,在计算机对该域名访问时 仍然不会连接dns服务器获取最新解析信息,会根据自己计算机上保存的缓存对应关系来解析,这样就会出现dns解析故障。

*.com分别用不同的连接方式。

functionFindProxyForURL(url,host)

{

if(isPlainHostName(host))

return"DIRECT";

elseif(shExpMatch(host,"*.com"))

return"PROXYcomproxy:80";

elseif(shExpMatch(host,"*.edu"))

return"PROXYeduproxy:80";

else

return"PROXYproxy:80";

}

f、url.substring(),本例演示根据不同的协议来选择不同的代理,http、https、ftp、

gopher分别使用不同的代理。

functionFindProxyForURL(url,host)

{

if(url.substring(0,5)=="http:"){

return"PROXYproxy:80";

}

elseif(url.substring(0,4)=="ftp:"){

return"PROXYfproxy:80";

}

elseif(url.substring(0,7)=="gopher:"){

return"PROXYgproxy";

}

elseif(url.substring(0,6)=="https:"){

return"PROXYsecproxy:8080";

}

else{

return"DIRECT";

}

}

g、dnsResolve(host),本例演示判断访问主机是否某个IP,如果是就使用代理,否则直

接连接。

unctionFindProxyForURL(url,host)

{

if(dnsResolve(host)=="166.111.8.237"){

return"PROXYsecproxy:8080";

}

pac自动代理脚本地址_创建pac自动代理文件_pac代理地址

else{

return"PROXYproxy:80";

}

}

h、myIpAddress(),本例演示判断本地IP是否某个IP,如果是就使用代理,否则直接使

用连接。

functionFindProxyForURL(url,host)

{

if(myIpAddress()=="166.111.8.238"){

return"PROXYproxy:80";

}

else{

return"DIRECT";

}

}

i、dnsDomainLevels(host),本例演示访问主机的域名级数是几级,就是域名有几个点

如果域名中有点,就通过代理访问,否则直接连接。

functionFindProxyForURL(url,host)

{

if(host==null||host.length()==0){。 * find client host name (or "0.0.0.0" if unknown) 。if(bind(s, (struct sockaddr *) &host, sizeof(host)) < 0) {。

return"PROXYproxy:80";

}

return"DIRECT";

}

j、weekdayRange(),本例演示当前日期的范围来改变使用代理,如果是GMT时间周三

到周六,使用代理连接,否则直接连接。

functionFindProxyForURL(url,host)

{

if(weekdayRange("WED","SAT","GMT"))

return"PROXYproxy:80";

else

return"DIRECT";

}

k、最后一个例子是演示随机使用代理,这样可以好好利用代理服务器。

functionFindProxyForURL(url,host)

{

returnrandomProxy();

}

functionrandomProxy()

{

switch(Math.floor(Math.random()*5))

{

case0:

return"PROXYproxy1:80";

创建pac自动代理文件_pac代理地址_pac自动代理脚本地址

break;

case1:

return"PROXYproxy2:80";

break;

case2:

return"PROXYproxy3:80";

break;

case3:

return"PROXYproxy4:80";

break;

case4:

return"PROXYproxy5:80";

break;

}

}

例子:最后保存的扩展名为pac

functionFindProxyForURL(url,host)

{

/* check if target_type is a direct ancestor of type */ while (type) { if (type == target_type) { return true。修改:#if 0if ((hp = gethostbyname(host)) == null) { //mhb 2013-10-22error("can't get host address for host %s: errno %d", host, errno)。remove and return an item from the queue. if optional args block is true (the default) and timeout is none (the default), block if necessary until an item is available. if timeout is a positive number, it blocks at most timeout seconds and raises the queue.empty exception if no item was available within that time. otherwise (block is false), return an item if one is immediately available, else raise the queue.empty exception (timeout is ignored in that case).。

elseif(isInNet(host,"61.28.0.0","255.255.240.0"))return"DIRECT";

elseif(isInNet(host,"61.48.0.0","255.248.0.0"))return"DIRECT";

elseif(isInNet(host,"61.128.0.0","255.192.0.0"))return"DIRECT";

.

.

.

elseif(isInNet(host,"192.168.100.0","255.255.0.0"))return"DIRECT";

elsereturnrandomProxy();

}//代理调度函数,代理列表加在这里

//注意代理格式,代理之间用逗号隔开

functionrandomProxy()

{

varproxyList=newArray(

"PROXY61.152.210.150:3128",

.

.

.

"PROXY61.152.210.150:3128",

//可以只写一个,建议);//生成一个0到proxyList.length-1的随机数

varindex=Math.floor(Math.random()*proxyList.length);//alert(proxyList[index]);

returnproxyList[index];

//return"DIRECT";

}做完之后,可以放到网上,可以在本地机器上。

比如保存为C:\myproxy.pac。之后在IE或者Netscape

在使用脚本上网方式时,在切换代理的过程中,虽然花刺代理软件能自动修改脚本的代理地址pac自动代理脚本地址,但由于本人不知道firefox的消息机制,程序无法及时通知firefox浏览器, 因此在花刺切换代理后,要进入firefox里面的tools-->options-->connection settings-->reload按钮,然后按ok,这样firefox会重新获取新的脚本信息(也就是获取了新的代理信息),其实这个过程还是很方便,比使用本软件的“复制代理”方法要简单些。5> 添加了代理自动配置脚本功能,同时上国内和国外网不用来回切换代理,由浏览器自动判断是直通还是用代理上网。sockscap我想就不用多说了吧,如果你有socks代理,用了这个自然就能实现二级代理,不过socks代理倒是不多.而socks2http是用http代理模拟socks5代理. 比如用202.38.64.4:8080做socks代理,在socks2http设置中如是填入后,填入你的帐号和密码.再点击 "完成"即可.使用时,在你所用的软件中的socks5代理栏处 填入localhost,端口1080 .这样你所用的自然就是202.38.64.4的socks代理了. 或者运行sockscap,在socks代理设置中填localhost,注意只能用socks5,不能做socks4代理. 但用http模拟的socks代理限于很少的一些网络软件.http浏览没什么问题(注意ie4不支持sockacap),可telnet,ftp就不一定了,好像只有本身支持socks代理的软件才行.建议在telnet时使用sterm1.0,在ftp时用absoluteftp.(注意需要使用二级代理的软件,一定要在sockscap里运行,你所用的第一级代理才能生效)。