Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Proxyfinder

by Onur (Beadle)
on Dec 23, 2007 at 01:27 UTC ( [id://658726]=sourcecode: print w/replies, xml ) Need Help??
Category: Networking Code
Author/Contact Info Onur Aslan
Description: This program is not usable anymoreThis program finding proxies (getting from samair.ru/proxy) and optional pinging them. Example output:
IP   Port  Country  Status  Ping
129.69.210.96  3128  Germany  Online  101
193.196.39.10  3127  Germany  Online  103
141.76.45.17  3124  Germany  Online  104
80.156.84.39  80  Germany  Online  105
217.172.56.174  23  Germany  Online  107
80.156.84.38  80  Germany  Online  107
88.198.9.185  3128  Germany  Online  107
Example XML output:
<?xml version='1.0'?>
<opt complete_time="1198372633">
  <proxy ip="202.56.176.1" checktime="1198372568" country="Afghanistan" durum="Online" ping="678" port="3128" type="transparent proxy" />
  <proxy ip="196.202.252.244" checktime="1198372570" country="Angola" durum="Offline" ping="0" port="80" type="transparent proxy" />
  <proxy ip="200.81.25.5" checktime="1198372572" country="Argentina" durum="Offline" ping="0" port="3128" type="transparent proxy server" />
  <proxy ip="190.2.61.161" checktime="1198372572" country="Argentina" durum="Online" ping="316" port="80" type="high-anonymous proxy" />
  <proxy ip="201.234.107.165" checktime="1198372573" country="Argentina" durum="Online" ping="357" port="80" type="transparent proxy" />
  ...
</opt>
This program doesn't have any sort option. I dont know how can i short an array reference. You can sort output with `sort` command. For example if you want to sort ping column:
./proxyfinder.pl --text --ping | grep Online | sort -k 5
You can download latest version of this program:
cvs -d :pserver:anonim@0nur.net:/root checkout proxyfinder
This is my first post to here. Sorry for my bad English
#!/usr/bin/perl 
######################################################################
+###
# Proxyfinder 1.1 EN                                                  
+  #
#                                                                     
+  #
# Finding proxies and optional pinging them.                          
+  #
#                                                                     
+  #
# Arguments:                                                          
+  #
# --progress-bar=[0|1] Showing progress bar.                          
+  #
# --ping               Pinging them. Default 0                        
+  #
# Output format:                                                      
+  #
# --text     || --cikti=0  Text output. Default.                      
+  #
# --raw-text || --cikti=1  Raw text output (ip:port).                 
+  #
# --xml      || --cikti=2  XML output.                                
+  #
#                                                                     
+  #
# Example:                                                            
+  #
#   ./proxyfinder.pl --raw-text --ping                                
+  #
#                                                                     
+  #
# Proxyfinder 1.1 EN                                                  
+  #
# Copyright (C) 2007  Onur Aslan <onuraslan@gmail.com>                
+  #
#                                                                     
+  #
# This program is free software: you can redistribute it and/or modify
+  #
# it under the terms of the GNU General Public License as published by
+  #
# the Free Software Foundation, either version 3 of the License, or   
+  #
# any later version.                                                  
+  #
#                                                                     
+  #
# This program is distributed in the hope that it will be useful,     
+  #
# but WITHOUT ANY WARRANTY; without even the implied warranty of      
+  #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       
+  #
# GNU General Public License for more details.                        
+  #
#                                                                     
+  #
# You should have received a copy of the GNU General Public License   
+  #
# along with this program.  If not, see <http://www.gnu.org/licenses/>
+. #
######################################################################
+###

use strict;
use HTML::TokeParser;
use LWP::Simple;
use Net::Ping;

# Ayarlar
my $ping_at = 0;      # Proxyler bulunduktan sonra pinglensin mi?
my $cikti = 0;        # Cikti bicimi:
                      # Text = 0
                      # Raw text (ip:port) = 1
                      # XML = 2
my $progress_bar = 1; # Progress bar olsun mu olmasin mi
my $quiet = 0;        # Herhangi bir cikti gosterilmeden calissin mi?

# Bundan sonrasina karismaniza gerek yok

my $proxyler;
my $out;
my $progress;
local $| = 1;
$progress_bar = 0 if !eval "require Term::ProgressBar;" || $quiet == 1
+;
# Eger XML::Simple modulu bulunamazsa devam etmesi icin eval kullanild
+i
eval "use XML::Simple;";

sub proxybul
{
  my $sayfa = "01";
  my @raw_proxyler;
  my @raw_proxyler2;
  foreach (1..30)
    {
      my $url = "http://www.samair.ru/proxy/type-$sayfa.htm";
      my $icerik = get ($url);
      # Eger bir sayfa acilamazsa digerine geciyor
      if (!$icerik)
        {
          $progress->update () if $progress_bar;
          next;
        }
      my $html = HTML::TokeParser->new (\$icerik)
                   or die "File doesn't open: $!\n";
      while (my $icerik = $html->get_tag ("td"))
        {
          my $text  = $html->get_trimmed_text ("/td");
          $text =~ s/: /:/;
          if ($text !~ /IP address/
              && $text !~ /Anonymity level/
              && $text !~ /Checked time/
              && $text !~ /Country/)
            {
              push @raw_proxyler, $text;
            }
        }
      $sayfa++;
      $progress->update () if $progress_bar;
    }
  # Simdi proxyler cikariliyor
  print "\n" if $progress_bar && $ping_at;
  progressbar_yarat ("Pinging proxies", (($#raw_proxyler-1)/4)-1) if $
+ping_at;
  for (my $i = 0; $i < @raw_proxyler; $i = $i+4)
    {
      my $durum;
      my $ping_return;
      my $ping_duration;
      my ($proxy, $port) = $raw_proxyler[$i] =~ /(.*):(.*)/;
      if ($ping_at)
        {
          my $ping = Net::Ping->new ();
          $ping->hires ();
          ($ping_return, $ping_duration, $proxy) = $ping->ping ($proxy
+, 2);
          if ($ping_return)
            {
              $durum = "Online";
              $ping_duration = 1000 * $ping_duration;
              ($ping_duration) = $ping_duration =~ /([\d]*)\./;
            }
          else
            {
              $durum = "Offline";
              $ping_duration = 0;
            }
          $ping->close;
          $progress->update () if $progress_bar;
        }
      else
        {
          $durum = "Didn't pinged";
          $ping_duration = 0;
        }
      push @raw_proxyler2, {
        "ip" => $proxy,
        "port" => $port,
        "type" => $raw_proxyler[$i+1],
        "country" => $raw_proxyler[$i+3],
        "durum" => $durum,
        "ping" => $ping_duration,
        "checktime" => time
      }
    }
  $proxyler = { "complete_time" => time, "proxy" => [@raw_proxyler2] }
+;
}

sub xml
{
  $out = XMLout ($proxyler, KeyAttr => 'ip', XMLDecl => "<?xml version
+='1.0'?>")
}

sub raw_text
{
  foreach (@{$proxyler->{proxy}})
  {
    print $_->{ip}, ":", $_->{port}, "\n";
  }
}

sub text
{
  print "IP\t\t\tPort\t\tCountry\t\tStatus\t\tPing\n";
  foreach (@{$proxyler->{proxy}})
  {
    print $_->{ip}, "\t\t", $_->{port}, "\t\t", $_->{ulke}, "\t\t", $_
+->{durum},, "\t\t", $_->{ping}, "\n";
  }
}

sub conf_parse
{
  $_ = join (" ", @ARGV);
  if (/--version/)
    {
      print "Proxyfinder 1.0\nCopyrigt 2007 Onur Aslan - Licensend und
+er GPLv3\n";
      exit 0;
    }
  $ping_at = 1 if /--ping/;
  $cikti = $1 if /--cikti=([0|1|2])/;
  $cikti = 0 if /--text/;
  $cikti = 1 if /--raw-text/;
  $cikti = 2 if /--xml/;
  $progress_bar = $1 if /--progress-bar([0|1])/;
  $quiet = 1 && $progress_bar = 0 if /-q/ || /--quiet/;

}

sub progressbar_yarat
{
  if ($progress_bar)
    {
      $progress = Term::ProgressBar->new ({name => $_[0], count => $_[
+1], ETA => "linear"});
      $progress->max_update_rate (1);
    }
  else
    {
      print $_[0]."\n";
    }
}

sub goster
{
  text if $cikti == 0;
  raw_text if $cikti == 1;
  xml if $cikti == 2;
  print $out if !$quiet;
}


conf_parse;
progressbar_yarat "Getting proxies", 30;
proxybul;
goster;
0;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://658726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found