#!/usr/bin/perl -w use strict; use LWP::UserAgent::ProxyAny; use Time::HiRes qw(gettimeofday); #use Tie::File; #my $savefile = "/home/simon/proxy/ch/ips.txt"; #my (@a_lines, @ip_generator); my @ip_generator; my @ip; my @ports = (80, 8080); # ip address limit # 83.1.1.1 my $a_end = 82; my $b_end = 38; my $c_end = 88; my $d_end = 25; # ip address start # 82.1.1.1 my $a_start = 82; my $b_start = 38; my $c_start = 88; my $d_start = 3; my $ua = LWP::UserAgent::ProxyAny->new; my $url = "http://www.whatismyip.com/"; my $match = '([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'; &generate(); &portify(); &proxy_checker(); exit(0); sub portify { my $ips; if (@ip_generator) { foreach my $ip (@ip_generator) { foreach my $port (@ports) { $ips = $ip.":".$port; push @ip, $ips; #print $ips."\n"; } } } else { print "portify ~ error!\n"; exit(0); } } sub proxy_checker { if (@ip) { my $timeout = "1.5"; $ua->agent("proxytest.pl by bunker [http://rawlab.altervista.org]"); $ua->timeout($timeout); my (@anonymous, @anonreport, @transparent, @not_working); my $myip = &my_ip(); foreach my $proxy (@ip) { $ua->set_proxy_by_name("$proxy"); my $t0 = gettimeofday; my $request = $ua->get($url); my $t1 = gettimeofday; my $tdiff = sprintf "%0.3f", $t1-$t0; if ($request->is_success) { my $content = $request->content; if($content =~ m/$match/i) { my $ret_ip = $1; if ($proxy =~ m/^$myip:[0-9]/i) { print "$proxy is TRANSPARENT - Response time: $tdiff sec\n"; push @transparent, "$proxy ($tdiff sec)"; } else { print "$proxy is ANONYMOUS - Response time: $tdiff sec\n"; push @anonymous, "$proxy ($tdiff sec)"; push @anonreport, "$proxy"; } } else { print "Ooops!! Something wrong (Check matching string)!\n"; } } else { my $msg = $request->status_line; print "$proxy ($msg)\n"; push @not_working, "$proxy ($msg)"; } } } else { print "proxy_checker ~ error!\n"; exit(0); } } sub my_ip { $ua->set_proxy_by_name(""); $ua->no_proxy(); my $request = $ua->get($url); my $content = $request->content; my $ip = $1 if($content =~ m/$match/i); return $ip; } sub generate { my $valid; my $ip; my $calc1 = $a_start.".".$b_start.".".$c_start.".".$d_start; my $calc2 = $a_end.".".$b_end.".".$c_end.".".$d_end; my $ip1_int = unpack "N",pack "C4", split/\./,$calc1; my $ip2_int = unpack "N",pack "C4", split/\./,$calc2; if ($a_start<256 && $b_start<256 && $c_start<256 && $d_start<256 && $a_end<256 && $b_end<256 && $c_end<256 && $d_end<256) { if ($ip2_int<=$ip1_int) { print("ip_generator ~ error!\n"); #$valid = 0; exit(0); } else { $valid = 1; print $ip1_int." = ip1 = ".$calc1."\n"; print $ip2_int." = ip2 = ".$calc2."\n"; } } else { print "ip_generator ~ error!\n"; #$valid = 0; exit(0); } while ($valid==1) { $ip = $a_start.".".$b_start.".".$c_start.".".$d_start; push @ip_generator, "$ip"; #print $ip."\n"; if ($a_start==$a_end && $b_start==$b_end && $c_start==$c_end && $d_start==$d_end) { $valid = 0; } if ($b_start==255 && $c_start==255 && $d_start==255) { $a_start++; $b_start = 0; $c_start = 0; $d_start = 0; } elsif ($c_start==255 && $d_start==255) { $b_start++; $c_start = 0; $d_start = 0; } elsif ($d_start==255) { $c_start++; $d_start = 0; } else { $d_start++; } } #tie @a_lines, 'Tie::File', "$savefile", or die "$savefile file problem: $!"; #push @a_lines, @ip_generator; #untie @a_lines; }