会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
首页
订阅
管理
[php]将cnproxy的代理列表转成GB的 (20060910更新)
<?php <?php require_once("echo.php"); set_time_limit(0); //$nvfile="http://www.cnproxy.com/proxy1.html"; $nvfile = "proxy1.html"; $data=file_get_contents ( $nvfile ); //$rt = file_put_contents ( "proxy.html", $data); $from = '<table>'; $to = '</table>'; $data = preg_match("#$from.*?$to#s",$data,$match); $match[0] = str_replace("","",$match[0]); //prt($match); $trs = split("\r\n",$match[0]); //$trs = preg_match("#<tr>.*?</tr>#si",$match[0],$matchtrs); $n=count($trs); $k=1; $proxyString=""; $ips = array(); for ($i=2;$i<$n ;$i++ ) { $tr = $trs[$i]; $tds = split("</td><td>",$tr); if ($tds[1]=="HTTP") { $ip = substr($tds[0],8); //echot($ip); $ips[$i]['ip'] = $ip; $name = substr($tds[3],0,-10); //$name .= "_".$i;//echot($name); $ips[$i]['name'] = $name; //prt($tds); $proxyString .="proxy".$k."=http://".$ip."\r\n" ; $proxyString .="speed".$k."=3\r\n"; $proxyString .="alias".$k."=".$name."\r\n"; $k++; } } echot($proxyString,500,100); return; //探测速度。 $timeout = 1; $speed=array(); //未超时的站点 $speedIndex=array(); //索引 $speed_d=array(); //超时的站点 $i=0; $d=0; foreach ($ips as $ip) { $ipa = split(":",$ip['ip']); $target = $ipa[0]; $port = $ipa[1]; $timeStart = getmicrotime(); $fp = fsockopen ( $target, $port , $errno , $errstr , $timeout); $timeEnd = getmicrotime(); if ($fp!==false) { $speed[$i]['ip']=$ip['ip']; $speed[$i]['time'] = ($timeEnd-$timeStart); $speed[$i]['name'] = $ip['name']; //索引 $speedIndex[$i] = $speed[$i]['time']; $i++; fclose($fp); } else { $speed_d[$d]['ip']=$ip['ip']; $speed_d[$d]['time'] = ($timeEnd-$timeStart); $speed_d[$d]['name'] = $ip['name']; $d++; } //if ($i>5)break; } //对探测的结果索引排序,不改变key asort($speedIndex,SORT_NUMERIC); $k=1; $proxyString = ''; foreach ($speedIndex as $sikey=>$siv) { //echo $sikey."=".$siv."<br/>\n"; $ip = $speed[$sikey]['ip']; $name = $speed[$sikey]['name']."_$k"."_".substr($speed[$sikey]['time'],0,4); $proxyString .="proxy".$k."=http://".$ip."\r\n" ; $proxyString .="speed".$k."=3\r\n"; $proxyString .="alias".$k."=".$name."\r\n"; $k++; } echot($proxyString,400,200); $rt = file_put_contents ( "proxy".date("H_i_s").".ini", $proxyString); $file = "D:\tools\网络工具\browser\GreenBrowserGB\User\Proxy.ini.tpl"; $data=file_get_contents ( $file ); $data = str_replace("{proxyString}",$proxyString,$data); $pxfile = "D:\tools\网络工具\browser\GreenBrowserGB\User\Proxy.ini"; $pxbkfile = "D:\tools\网络工具\browser\GreenBrowserGB\User\Proxy.ini".date("Y-m-d-H-i-s").".bak"; copy($pxfile,$pxbkfile); $rt = file_put_contents ( $pxfile, $data); //prt($speedIndex); //prt($speed); //prt($trs); /* $proxyString .="proxy".$k."=http://".$ip."\r\n" ; $proxyString .="speed".$k."=3\r\n"; $proxyString .="alias".$k."=".$name."\r\n"; */ ?> <!-- proxy26=http://218.244.225.180:80 speed26=3 alias26=北京 -->
Posted on
2005-12-26 09:26
古代
阅读(
356
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部