Updated version for your viewing pleasure. You were right about having redundancy so I compacted the 3 diff subs into one sub that just loops through an array of the target proxylisters. It also looks much cleaner. Applied use strict and use warnings but still get an odd warning, see other post. I've also changed the arrays used, thanks for that one too. See readmore for actual code.
#!/usr/bin/perl # ProxyHunter 0.2 # By Sock (http://www.socklabs.com) # ChangeLog # 18.5.2004 First release use strict; use warnings; use LWP::UserAgent; use HTTP::Request::Common; use Getopt::Long; my $opt_page = 1; our %info = (version => "0.3", format => 0, agent => "Sock's Proxy Hunter/0.3", clear => 0, anonymous => 0, spranonymous => 1, elite => 1 ); our @data; our @marks; # Lets define the data structure for the proxy array # ip/host, port, type, country, anon level, use (0 no:1 yes) push @data, ["127.0.0.1", "8080", "http", "USA", "Anonymous", "0"]; push @data, ["127.0.0.2", "8081", "socks5", "USA", "Highly Anonymous", + "0"]; # Name, target page, clear all whitespace (1 yes, 0 no) push @marks, [1, "Stayinvisible.com", "http://www.stayinvisible.com/in +dex.pl/proxy_list?order=&offset=0", 1]; push @marks, [1, "PublicProxyServer.com", "http://www.publicproxyserve +rs.com/page1.html", 1]; push @marks, [1, "Proxy4Free.com", "http://www.proxy4free.com/page1.ht +ml", 1]; print <<"EOF"; ProxyHunter $info{version} (c) 2003-2004 Sock Released without warranty under the terms of the Artistic License. EOF our $opt_debug; our $opt_format; our $opt_verbose; GetOptions("help|?",\&showhelp, "debug", \$opt_debug, "page=s", \$opt_ +page, "output=s", \$opt_format, "verbose|v", \$opt_verbose); sub showhelp() { print << "EOF" ; Usage: $0 [options] dir1 dir2 file1 file2 ... Options: --debug Show extra debug information --spage=x Set the page to read from on the stayinvis website. Not U +sed --output=x Set the output format. See examples: [0] 192.168.1.1 80 [1] http 192.168.1.1 8080 # Highly Anonymous - Russia [2] 192.168.1.1:80\@http --help Display this help message EOF exit; } our $debug = $opt_debug; our $format = $opt_format ? $opt_format : $info{format}; our $t = 0; print "Debug option set.\n" if ($debug); #stayinvis(); markloop(); sub markloop() { foreach my $m (@marks) { if ($m->[0] == 1) { print "[+Scan] Starting engine for $m->[1]\n"; print " [Debug] Initilizing agent.\n" if ($debug); my $proxhunter = LWP::UserAgent->new(); $proxhunter->agent($info{agent}); print " [Debug] Retrieving site: $m->[2].\n" if ($debug); my $http_res = $proxhunter->request(POST $m->[2]); my $stuff = $http_res->content; print " [Debug] Error, failed.\n" and return unless ($http +_res->is_success); if ($m->[3] == 1){ print " [Debug] Removing white spaces.\n" if ($debug); $stuff =~ s/\s//g; } print " [Debug] Sifting through results.\n" if ($debug); while ($stuff =~ m/<td[^>]*>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d +{1,3})<\/td><td[^>]*>(\d{1,5})<\/td><td[^>]*>(\w*)<\/td><td[^>]*>(\w* +)<\/td>/g) { $t++; my $use_this = 0; for ($3) { m/transparent/ && $info{clear} == 1 && do {$use_th +is = 1; last;}; m/anonymous/ && $info{anonymous} == 1 && do {$use_ +this = 1; last;}; m/highanonymity/ && $info{spranonymous} == 1 && do + {$use_this = 1; last;}; } # print " [Debug] Found: $1, $2, $3, $4, $5, use $use_t +his\n" if ($debug); push @data, ["$1", "$2", "http", "$3", "$4", "$use_thi +s"]; } print "[-Scan] Stopping engine for $m->[1]\n\n"; } } } #my $good_proxy_count = scalar(@good_proxies); (my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my + $yday, my $isdst)=localtime(time); $mon++; my $g; my $outfile = "n$min"."h$hour"."d$mday"."m$mon".".proxylist"; print "Setting output file as $outfile.\n" if ($debug); open(fileOUT, ">>$outfile"); foreach my $d (@data) { if ($d->[5] == 1) { $g++; if ($format == 0) {print fileOUT "$d->[0]:$d->[1]\n";} if ($format == 1) {print fileOUT "$d->[2]\t$d->[0]:$d->[1] #$d->[3 +] - $d->[4]\n";} if ($format == 2) {print fileOUT "$d->[0]:$d->[1]\@$d->[2]\n";} } } close(fileOUT); print "All tasks complete. Loaded $g out of $t proxies.\n"; exit;
-----
Guns don't kill people, ninjas do.

In reply to Re^2: Code optomization by sock
in thread Code optomization by sock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.