Added script findproxy.

This just tries a list of proxies and chooses the fastest one.
This commit is contained in:
hjp 2008-05-02 08:13:57 +00:00
parent 64863e9553
commit 8f74fc527d
1 changed files with 31 additions and 0 deletions

31
findproxy/findproxy Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/perl
use warnings;
use strict;
use LWP::UserAgent;
use Time::HiRes qw(time);
my $verbose = 0;
my $ua = LWP::UserAgent->new();
my @proxies;
for my $proxy (@ARGV) {
print STDERR "trying proxy $proxy\n" if $verbose;
$ua->proxy('http', $proxy);
my $t0 = time();
my $response = $ua->get('http://www.hjp.at');
if ($response->is_success) {
my $dt = time() - $t0;
print STDERR "\tsucceded in $dt seconds\n" if $verbose;
push @proxies, [ $dt, $proxy ];
} else {
print STDERR "\tfailed\n" if $verbose;
}
}
if (@proxies) {
@proxies = sort { $a->[0] <=> $b->[0] } @proxies;
print $proxies[0]->[1], "\n";
} else {
print STDERR "no proxies found\n" if $verbose;
}