From 8f74fc527d7b2ab894e21e6508d98682dd7275d0 Mon Sep 17 00:00:00 2001 From: hjp Date: Fri, 2 May 2008 08:13:57 +0000 Subject: [PATCH] Added script findproxy. This just tries a list of proxies and chooses the fastest one. --- findproxy/findproxy | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 findproxy/findproxy diff --git a/findproxy/findproxy b/findproxy/findproxy new file mode 100755 index 0000000..9bc4efc --- /dev/null +++ b/findproxy/findproxy @@ -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; +}