教育网IP地址获取及转换程序
2009-04-16 | 11:10wget --no-proxy --no-check-certificate https://www.nic.edu.cn/RS/ipstat/cernet-ipv4.txt或者使用lynx(需要在lynx.cfg文件中设置FORCE_SSL_PROMPT:YES):
然后就可以对该文件进行处理了:
#!/usr/bin/perl -w
use Net::IP;
use File::Find;
use IO::File;
use Cwd;
my $fh1;
my $fs1 = "cernet-ipv4.txt";
my $ip;
open ($fh1, "< $fs1") or die "Could not open $fs1 for reading: $!n";
while (defined($lines = readline $fh1)){
if ($lines =~ /d+.d+.d+.d+/d+/) { ###匹配xxx.xxx.xxx.xxx/xx形式的IP地址
$lines =~ s/As+|s+z//g; ###去掉字符串前面和后面的空格
$ip = new Net::IP ($lines) or die (Net::IP::Error());
# print ($ip->ip()."/".$ip->mask()."n"); ###转换成掩码方式
# print ($ip->ip()."-".$ip->last_ip()."n"); ###转换成IP地址段
# print ("ip route add $lines via $gateway table mainn"); ###生成修改路由脚本
print ("else if (isInNet(host,"".$ip->ip()."","".$ip->mask()."")) return "PROXY xxx.xxx.xxx.xxx:3128;PROXY yyy.yyy.yyy.yyy:3128;DIRECT";n"); ###生成pac脚本内容
}
}
close ($fh1);上述代码需要安装Perl的Net::IP模块。











最新评论