首页 > 技术贴 > 又一个小东西

又一个小东西

2008年4月16日

教育网上公网就是郁闷,网速慢不说,还n多网站上不去。。。。

学校提供了一个代理,网通/教育网双线。用起来还不错,上公网,教育网都很快,就是有限速,256kbps,而且不支持ipv6。老挂着也不是办法。

于是自己想发法子写的两个代理自动配置脚本。教育网的地址,以及教育网内访问很快的网址(我所知道的),都不走代理,其他统统走代理出去。顺带做了点手脚,解决的blogspot的访问问题。。。

教育网地址列表通过http://www.nic.edu.cn/RS/ipstat/cernet-ipv4.txt每天更新。话说这个东西好像更新速度也没这么快来着。。。根据上面的数据,计算出子网掩码,然后生成pac脚本。生成脚本用的php文件
http://www.fengxinzi.net/tool/proxy/proxy.php

自己现在用着,速度还挺爽的~~~

顺便发论坛,服务大众,呵呵。

http://forum.byr.edu.cn/wForum/disparticle.php?boardName=NetResources&ID;=34586

效果截图:

proxy

php源码:
< ?PHP$time='//'.date("Ymd");$file_dir="cache.dat";if(file_exists($file_dir)){ $fp=fopen($file_dir,"r"); $ftime=fread($fp,10); if($ftime==$time){  $str=fread($fp,filesize($file_dir)-10); fclose($fp); } else{ fclose($fp);  $str = cache($file_dir,$time); }}else{ $str = cache($file_dir,$time);}echo($str);

function cache($file_dir,$time){ $rst = @file_get_contents("byr.dat"); $ipdata = file("http://www.nic.edu.cn/RS/ipstat/cernet-ipv4.txt"); $ipformat = "^(([0-9]{1,2})(1[0-9][0-9])(2[0-4][0-9])(25[0-5])).(([0-9]{1,2})(1[0-9][0-9])(2[0-4][0-9])(25[0-5])).(([0-9]{1,2})(1[0-9][0-9])(2[0-4][0-9])(25[0-5])).(([0-9]{1,2})(1[0-9][0-9])(2[0-4][0-9])(25[0-5]))/[0-9]{1,2}$"; $endstr = ' else  return "PROXY proxy.bupt.edu.cn:8080; DIRECT";  }else return "DIRECT";}'; for($i = 0; $i < count($ipdata); $i++){  $ipdata[$i] = trim($ipdata[$i]); if(ereg($ipformat,$ipdata[$i])) {   $ip= explode('/',$ipdata[$i]);   $mask = netmask($ip[1]);   $rst = $rst.(' else if(isInNet(host,"'.$ip[0].'","'.$mask.'"))  return "DIRECT";'."rn"); //echo($ip[0]."    ".$mask."rn");  } } $rst = $time."rn".$rst.$endstr; $fp=fopen($file_dir,"w"); fwrite($fp,$rst); fclose($fp); return $rst;}

function netmask($num){ $masks=array(0,0,0,0); $n = 0; for($i = $num; $i >= 0; $i = $i-8){ if($i >=8 ) $masks[$n]=255; else $masks[$n] = 256 - pow(2,(8-$i));  $n = $n + 1; } $rst = $masks[0].'.'.$masks[1].'.'.$masks[2].'.'.$masks[3]; return($rst);}?>

代码打包下载

分类: 技术贴 标签:
  1. 小恐龙
    2008年4月17日22:24 | #1

    大哥,你写的博客都这么有水平,简直太高深了.

  2. 2008年4月19日08:21 | #2

    See Please Here

本文的评论功能被关闭了.