|
|
发表于 2006-5-22 08:53:52
|
显示全部楼层
[PHP]#!/usr/bin/perl
#use strict;
$m=0;
foreach(@ARGV){
$m++;
}
if($m != 1){
die "Usage:proxycat www.example.com\nThen U will get the fastest proxy to www.example.com!\n";
}
use LWP::Simple;
my $content = get("http://lqqm.net/cgi-bin/proxylist");
$_=$content;
$i=0;
for (;/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,8})/sg;){
push(@proxy,$1);
$i++;
}
print "We've found $i proxy!\n";
system "echo > wget.log";
for($j=0;$j<$i;$j++){
system "export http_proxy=http://$proxy[$j];wget -P /tmp -T 6 -t 1 -Y on -a wget.log @ARGV";
if ($? eq 0){
print "We've got one! proxy$j proxy[$j]\n";
system "echo got proxy[$j] >> wget.log";
}
}
open WGET, "wget.log";
@wget=<WGET>;
system "echo > grep";
$n=0;
foreach $wget (@wget){
if ($wget=~ /got\ \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,8})/){
$n++;
$ip[$n]=$1;
}
}
print "We got $n ip!\n";
$n=0;
foreach $wget (@wget){
if ($wget=~ /\((\d+\.\d+)\s+(K|M)?B\/s\).+?saved/){
if ($wget=~ /\((\d+\.\d+)\s+MB\/s\).+?saved/){
$temp=1024 * $1;
}elsif ($wget=~ /\((\d+\.\d+)\s+B\/s\).+?saved/){
$temp=$1/1024;
}else{
$temp=$1;
}
$n++;
$v[$n]=$temp;
}
}
print "We got $n v!\n";
for ($j=1;$j<=$n;$j++){
$hash_ip_v{$ip[$j]}=$v[$j];
print "$ip[$j]----->$hash_ip_v{$ip[$j]} KB\/s\n";
}
@hash= values%hash_ip_v;
$maximum=&max(@hash);
print "maximun is maximum KB\/s\n";
%hash_v_ip=reverse %hash_ip_v;
print "The best proxy is $hash_v_ip{$maximum}\n";
sub max {
my($max_so_far)=shift @_;
foreach (@_){
if($_ > $max_so_far){
$max_so_far=$_;
}
}
$max_so_far;
}
[/PHP]
save as proxycat;
#chmod +x proxycat
if you want some proxy for www.google.com
#./proxycat www.google.com |
|