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

上传人:子 文档编号:41835126 上传时间:2018-05-31 格式:DOC 页数:8 大小:32KB
返回 下载 相关 举报
局域网设置自动配置脚本文件的写法与用途_第1页
第1页 / 共8页
局域网设置自动配置脚本文件的写法与用途_第2页
第2页 / 共8页
局域网设置自动配置脚本文件的写法与用途_第3页
第3页 / 共8页
局域网设置自动配置脚本文件的写法与用途_第4页
第4页 / 共8页
局域网设置自动配置脚本文件的写法与用途_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《局域网设置自动配置脚本文件的写法与用途》由会员分享,可在线阅读,更多相关《局域网设置自动配置脚本文件的写法与用途(8页珍藏版)》请在金锄头文库上搜索。

1、局域网设置自动配置脚本文件的写法与用途局域网设置自动配置脚本文件的写法与用途局域网设置自动配置脚本文件的写法与用途:因为有朋友在深圳大学,他们学校的网络比较变态。如果访问了教育网指定的免费 IP 之外的 IP,每 M 6 元钱。 我本来想教她用二级代理之类的,不过无奈这个对她来讲太难了。所以权宜之下,我只好让她使用 IE 的自动配置脚本文件来限制以防万一,至少能保证她在使用浏览器上网的时候不会因为不小心访问了收费的 IP 而挨宰。虽然说这么变态的学校不多,但是终究还是有的,所以把自动配置脚本文件的写法写出来,如果有需要的朋友可以参考着来。 首先我们先来介绍一下自动配置脚本文件: 打开 IE,点

2、击“工具“-“Internet 选项“局域网设置“,你就可以看到“使用自动配置脚本“ 自动配置脚本起的作用就是,当 IE 访问网页的时候会根据脚本文件里面界定的内容来访问。比方说,你在脚本文件里面限定了访问某些 IP 使用某个代理的时候,访问另外一些 IP 使用另外的代理,这就很方便通过脚本文件来完成。 一个 PAC 文件其实就是一个文本文件,最简单的格式就是包含一个叫 FindProxyForURL 的 JScript 函数,IE 通过传入两个变量来调用这个函数,一个是用户浏览的地址 URL 全路经,一个是这个 URL 中的主机名部分(host)。 这个 FindProxyForURL 函数

3、有三种可能的字符串返回值,一是“DIRECT“,就是直接连接,不通过代理;二是“PROXY proxyaddr:port“,其中proxyaddr 和 port 分别是代理的地址和代理的端口;三是“SOCKS socksaddr:port“,其中 socksaddr 和 port 分别是 socks 代理的地址和端口,一个自动代理文件可以是多个选择的组合,其中用分号(;)隔开,如:function FindProxyForURL(url,host) if (host = ““) return “DIRECT“; return “PROXY myproxy:80; PROXY myotherpr

4、oxy:8080; DIRECT“; 下面是代理脚本可能用到的函数和说明(英文不好的朋友可以直接跳过去看应用): PAC Helper Functions dnsDomainIs(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 spe

5、cified 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

6、 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) Return

7、s a string containing the IP address of the specified host. myIPAddress( ) Returns a string containing the local machines 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

8、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. 下面是各个

9、函数应用的例子: 2 自动配置脚本文件的写法与用途:a、isPlainHostName(host),本例演示判断是否为本地主机,如 http:/myservername/ 的方式访问,如果是直接连接,否则使用代理 function FindProxyForURL(url, host) if (isPlainHostName(host) return “DIRECT“; else return “PROXY proxy:80“; b、dnsDomainIs(host, “)、localHostOrDomainIs(host, “),本例演示判断访问主机是否属于某个域和某个域名,如果属于 域的主机

10、名,而域名不是 和 的直接连接,否则使用代理访问。 function FindProxyForURL(url, host) if (isPlainHostName(host) dnsDomainIs(host, ““) else return “PROXY proxy:80“; c、isResolvable(host),本例演示主机名能否被 dns 服务器解析,如果能直接访问,否则就通过代理访问。 function FindProxyForURL(url, host) if (isResolvable(host) return “DIRECT“; else return “PROXY pro

11、xy: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 Fi

12、ndProxyForURL(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 分别使用不同的代理。 funct

13、ion 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 ret

14、urn “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 (my

15、IpAddress() = “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、最后一个例子

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号