脚本写法:局域网设置自动配置脚本文件的写法和用途

有朋友在深圳大学他们学校网络比较变态如果访问了教育网指定免费IP的外IP每M 6元钱
我本来想教她用 2级代理的类不过无奈这个对她来讲太难了所以权宜的下我只好让她使用IE自动配置脚本文件来限制以防万至少能保证她在使用浏览器上网时候不会不小心访问了收费IP而挨宰
虽然说这么变态学校不多但是终究还是有所以把自动配置脚本文件写法写出来如果有需要朋友可以参考着来
首先我们先来介绍下自动配置脚本文件:
打开IE点击"工具"--"Internet选项"--"局域网设置"你就可以看到"使用自动配置脚本"
自动配置脚本起作用就是当IE访问网页时候会根据脚本文件里面界定内容来访问比方说你在脚本文件里面限定了访问某些IP使用某个代理时候访问另外些IP使用另外代理这就很方便通过脚本文件来完成
个PAC文件其实就是个文本文件最简单格式就是包含个叫FindProxyForURLJScriptIE通过传入两个变量来这个个是用户浏览地址URL全路经个是这个URL中主机名部分(host)
这个FindProxyForURL有 3种可能串返回值是"DIRECT"就是直接连接不通过代理; 2是"PROXY proxyaddr:port"其中proxyaddr和port分别是代理地址和代理端口; 3是"SOCKS socksaddr:port"其中socksaddr和port分别是socks代理地址和端口个自动代理文件可以是多个选择组合其中用分号(;)隔开如:
function FindProxyForURL(url,host)
{
(host "www.mydo.com")
"DIRECT";
"PROXY myproxy:80;
PROXY myotherproxy:8080;
DIRECT";
}
下面是代理脚本可能用到和介绍说明(英文不好朋友可以直接跳过去看应用):
PAC Helper Functions
dnsDoIs(host, do) Returns true the host is part of the specied do, false otherwise.
isInNet(hostname, Resolves the hostname and subnet IP, subnet mask) s true the hostname is within the subnet
specied by the IP address and the subnet mask, false otherwise.
isPlainHostName(host) Returns true there are no dots in the hostname, false otherwise.
isResolvable(host) Internet Explorer tries to resolve the hostname through DNS and s true successful, false otherwise.
localHostOrDoIs Returns true the host matches (host, do) the host portion of the do, or the host matches the host and do portions of the do, false otherwise. (Executed _disibledevent=> "PROXY proxy:80";
}
(url.sub(0, 4) "ftp:") {
"PROXY fproxy:80";
}
(url.sub(0, 7) "gopher:") {
"PROXY gproxy";
}
(url.sub(0, 6) "https:") {
"PROXY secproxy:8080";
}
{
"DIRECT";
}
}
g、dnsResolve(host)本例演示判断访问主机是否某个IP如果是就使用代理否则直接连接
unction FindProxyForURL(url, host)
{
(dnsResolve(host) "166.111.8.237") {
"PROXY secproxy:8080";
}
{
"PROXY proxy:80";
}
}
h、myIpAddress本例演示判断本地IP是否某个IP如果是就使用代理否则直接使用连接
function FindProxyForURL(url, host)
{
(myIpAddress "166.111.8.238") {
"PROXY proxy:80";
}
{
"DIRECT";
}
}
i、dnsDoLevels(host)本例演示访问主机域名级数是几级就是域名有几个点如果域名中有点就通过代理访问否则直接连接
function FindProxyForURL(url, host)
{
(dnsDoLevels(host) > 0) { // number of dots in host > 0
"PROXY proxy:80";
}
"DIRECT";
}
j、weekdayRange本例演示当前日期范围来改变使用代理如果是GMT时间周 3到周 6使用代理连接否则直接连接
function FindProxyForURL(url, host)
{
(weekdayRange("WED", "SAT", "GMT"))
"PROXY proxy:80";

"DIRECT";
}
k、最后个例子是演示随机使用代理这样可以好好利用代理服务器
function FindProxyForURL(url,host)
{
randomProxy;
}
function randomProxy
{
switch( Math.floor( Math.random * 5 ) )
{
0:
"PROXY proxy1:80";
;
1:
"PROXY proxy2:80";
;
2:
"PROXY proxy3:80";
;
3:
"PROXY proxy4:80";
;
4:
"PROXY proxy5:80";
;
}
}
利用上面和例子介绍说明大家就可以写出比较复杂有效自动代理脚本
Tags:  自动配置脚本 使用自动配置脚本 脚本写法

延伸阅读

最新评论

发表评论