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";
}

下面是代理脚本可能用到的函数和说明(英文不好的朋友可以直接跳过去看应用): 

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
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.


下面是各个函数应用的例子: 
a、 isPlainHostName(host),本例演示判断是否为本地主机,如 http://myservername/ 的方式访问,如果是直接连接,否则使用代理
Js代码  


function FindProxyForURL(url, host)  
{  
if (isPlainHostName(host))  
return "DIRECT";  
else  
return "PROXY proxy:80";  
}  
 

b、 dnsDomainIs(host, "")、localHostOrDomainIs(host, ""),本例演示判断访问主机是否属于某个域和某个域名,如果属于.company.com域的主机名,而域名不是company.com和home.company.com的直接连接,否则使用代理访问。
Js代码  


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服务器解析,如果能直接访问,否则就通过代理访问。
Js代码  


function FindProxyForURL(url, host)  
{  
if (isResolvable(host))  
return "DIRECT";  
else  
return "PROXY proxy:80";  
}  
 

d、 isInNet(host, "", ""),本例演示访问IP是否在某个子网内,如果是就直接访问,否则就通过代理,例子演示访问清华IP段的主页不用代理。
Js代码  


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分别用不同的连接方式。
Js代码  


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分别使用不同的代理。
Js代码  


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,如果是就使用代理,否则直接连接。
Js代码  


unction FindProxyForURL(url, host)  
{  
if (dnsResolve(host) == "166.111.8.237") {  
return "PROXY secproxy:8080";  
}  
else {  
return "PROXY proxy:80";  
}  
}  
 

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


function FindProxyForURL(url, host)  
{  
if (myIpAddress() == "166.111.8.238") {  
return "PROXY proxy:80";  
}  
else {  
return "DIRECT";  
}  
}  

i、 dnsDomainLevels(host),本例演示访问主机的域名级数是几级,就是域名有几个点如果域名中有点,就通过代理访问,否则直接连接。
Js代码  


function FindProxyForURL(url, host)  
{  
if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0  
return "PROXY proxy:80";  
}  
return "DIRECT";  
}  
 

j、 weekdayRange(),本例演示当前日期的范围来改变使用代理,如果是GMT时间周三到周六,使用代理连接,否则直接连接。
Js代码  


function FindProxyForURL(url, host)  
{  
if(weekdayRange("WED", "SAT", "GMT"))  
return "PROXY proxy:80";  
else  
return "DIRECT";  
}  
 

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


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;  
}  
}  

常用正则表达式

匹配中文字符的正则表达式: [u4e00-u9fa5] 
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 

匹配双字节字符(包括汉字在内):[^x00-xff] 
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1) 

匹配空白行的正则表达式:ns*r 
评注:可以用来删除空白行 

匹配HTML标记的正则表达式:< (S*?)[^>]*>.*?|< .*? /> 
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力 

匹配首尾空白字符的正则表达式:^s*|s*$ 
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式 

匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)* 
评注:表单验证时很实用 

匹配网址URL的正则表达式:[a-zA-z]+://[^s]* 
评注:网上流传的版本功能很有限,上面这个基本可以满足需求 

匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$ 
评注:表单验证时很实用 

匹配国内电话号码:d{3}-d{8}|d{4}-d{7} 
评注:匹配形式如 0511-4405222 或 021-87888822 

匹配腾讯QQ号:[1-9][0-9]{4,} 
评注:腾讯QQ号从10000开始 

匹配中国邮政编码:[1-9]d{5}(?!d) 
评注:中国邮政编码为6位数字 

匹配身份证:d{15}|d{18} 
评注:中国的身份证为15位或18位 

匹配ip地址:d+.d+.d+.d+ 
评注:提取ip地址时有用 


匹配特定数字: 
^[1-9]d*$ //匹配正整数 
^-[1-9]d*$ //匹配负整数 
^-?[1-9]d*$ //匹配整数 
^[1-9]d*|0$ //匹配非负整数(正整数 + 0) 
^-[1-9]d*|0$ //匹配非正整数(负整数 + 0) 
^[1-9]d*.d*|0.d*[1-9]d*$ //匹配正浮点数 
^-([1-9]d*.d*|0.d*[1-9]d*)$ //匹配负浮点数 
^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$ //匹配浮点数 
^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$ //匹配非负浮点数(正浮点数 + 0) 
^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$ //匹配非正浮点数(负浮点数 + 0) 
评注:处理大量数据时有用,具体应用时注意修正 

匹配特定字符串: 
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串 
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串 
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串 
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串 
^w+$ //匹配由数字、26个英文字母或者下划线组成的字符串 

在使用RegularExpressionValidator验证控件时的验证功能及其验证表达式介绍如下: 
只能输入数字:“^[0-9]*$” 
只能输入n位的数字:“^d{n}$” 
只能输入至少n位数字:“^d{n,}$” 
只能输入m-n位的数字:“^d{m,n}$” 
只能输入零和非零开头的数字:“^(0|[1-9][0-9]*)$” 
只能输入有两位小数的正实数:“^[0-9]+(.[0-9]{2})?$” 
只能输入有1-3位小数的正实数:“^[0-9]+(.[0-9]{1,3})?$” 
只能输入非零的正整数:“^+?[1-9][0-9]*$” 
只能输入非零的负整数:“^-[1-9][0-9]*$” 
只能输入长度为3的字符:“^.{3}$” 
只能输入由26个英文字母组成的字符串:“^[A-Za-z]+$” 
只能输入由26个大写英文字母组成的字符串:“^[A-Z]+$” 
只能输入由26个小写英文字母组成的字符串:“^[a-z]+$” 
只能输入由数字和26个英文字母组成的字符串:“^[A-Za-z0-9]+$” 
只能输入由数字、26个英文字母或者下划线组成的字符串:“^\w+$” 
验证用户密码:“^[a-zA-Z]w{5,17}$”正确格式为:以字母开头,长度在6-18之间, 


只能包含字符、数字和下划线。 
验证是否含有^%&',;=?$"等字符:“[^%&',;=?$x22]+” 
只能输入汉字:“^[u4e00-u9fa5],{0,}$” 
验证Email地址:“^w+[-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$” 
验证InternetURL:“^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$” 
验证电话号码:“^((d{3,4})|d{3,4}-)?d{7,8}$” 


正确格式为:“XXXX-XXXXXXX”,“XXXX-XXXXXXXX”,“XXX-XXXXXXX”, 


“XXX-XXXXXXXX”,“XXXXXXX”,“XXXXXXXX”。 
验证身份证号(15位或18位数字):“^d{15}|d{}18$” 
验证一年的12个月:“^(0?[1-9]|1[0-2])$”正确格式为:“01”-“09”和“1”“12” 
验证一个月的31天:“^((0?[1-9])|((1|2)[0-9])|30|31)$” 


正确格式为:“01”“09”和“1”“31”。 


匹配中文字符的正则表达式: [u4e00-u9fa5] 
匹配双字节字符(包括汉字在内):[^x00-xff] 
匹配空行的正则表达式:n[s| ]*r 
匹配HTML标记的正则表达式:/< (.*)>.*|< (.*) />/ 
匹配首尾空格的正则表达式:(^s*)|(s*$) 
匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)* 
匹配网址URL的正则表达式:http://([w-]+.)+[w-]+(/[w- ./?%&=]*)? 

(1)应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1) 
String.prototype.len=function(){return this.replace([^x00-xff]/g,"aa").length;} 

(2)应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现 
String.prototype.trim = function() 

return this.replace(/(^s*)|(s*$)/g, ""); 

(3)应用:利用正则表达式分解和转换IP地址 
function IP2V(ip) //IP地址转换成对应数值 

re=/(d+).(d+).(d+).(d+)/g //匹配IP地址的正则表达式 
if(re.test(ip)) 

return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1 

else 

throw new Error("Not a valid IP address!") 


(4)应用:从URL地址中提取文件名的javascript程序 
s="http://www.jb51.net/page1.htm"; 
s=s.replace(/(.*/){0,}([^.]+).*/ig,"$2") ; //Page1.htm 
(5)应用:利用正则表达式限制网页表单里的文本框输入内容 
用正则表达式限制只能输入中文:onkeyup="value="/blog/value.replace(/["^u4E00-u9FA5]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))" 
用正则表达式限制只能输入全角字符: onkeyup="value="/blog/value.replace(/["^uFF00-uFFFF]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))" 
用正则表达式限制只能输入数字:onkeyup="value="/blog/value.replace(/["^d]/g,'') "onbeforepaste= "clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))" 
用正则表达式限制只能输入数字和英文:onkeyup="value="/blog/value.replace(/[W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''

在Windows下搭建DNS服务器

目前我找到的有两个软件可以达到要求,并且都能在Win7 X64上正常运行,他们分别是:BIND和Simple DNS Plus

前者是免费的,后者是收费的,貌似后者的操作要简便一些,但是不管怎样,能用就行,呵呵

Simple DNS Plus 5.2.121破解版下载地址:http://qiannao.com/file/linmao1/fa44429a/

BIND官方网站:https://www.isc.org/software/bind

Windows下查看和修改路由表的方法

运行CMD.EXE,打开命令提示符

查询路由表输入:

route print

添加路由规则输入:

route add AAA.AAA.AAA.AAA mask BBB.BBB.BBB.BBB CCC.CCC.CCC.CCC metric D if E

其中AAA.AAA.AAA.AAA是目标地址,BBB.BBB.BBB.BBB是子网掩码,CCC.CCC.CCC.CCC是网关,D是越点数,E是接口索引

删除路由规则输入:

route delete AAA.AAA.AAA.AAA mask BBB.BBB.BBB.BBB CCC.CCC.CCC.CCC metric D if E

其中AAA.AAA.AAA.AAA是目标地址,BBB.BBB.BBB.BBB是子网掩码,CCC.CCC.CCC.CCC是网关,D是越点数,E是接口索引

 

附带国家IP查询网站:www.blockacountry.com

无题微小说集 - 短短的文字却包含无限的感情

注:所有微小说均转载自网络

“你知不知道,我们两个月没有通电话了?” “两个月零七天” “为什么不给我打电话了?” “你有男朋友了” “有男朋友难道就不可以有男性朋友了嘛?” “你有男朋友心里话会对他说了,有什么事,他也会照顾你的,应该用不到我了。不是我不想联系,只是,我再也找不到打电话的理由。”

——再铁的异性朋友,当无论谁谈上恋爱,距离都会拉远。