8 # Checks routers for open socks-ports and socks5
9 # Successful connects go to STDOUT, failed ones to STDERR.
10 # We only do one check per loop in -d mode, so it takes some time.
12 # Contributed by Peter Kornherr <peter at wuschelpuschel dot org>, and
13 # cleaned up by Peter Palfrader <peter at palfrader dot org>.
15 our($opt_i,$opt_p,$opt_d,$opt_h,$opt_l);
18 if ($opt_h || !($opt_d||$opt_i||$opt_l)) {
19 print "Usage: $0 -d < file_with_routers_in_it\n";
20 print "or: $0 -i IP -p Port\n";
21 print "or: $0 -l IP:Port\n";
26 open (IN
,"<-") or die $!;
28 next unless /^router /;
29 (my $routername,my $checkip,my $checkport) = (split(" "))[1,2,4];
30 &do_check
($checkip,$checkport,$routername);
32 } elsif ($opt_i && $opt_p) {
33 &do_check
($opt_i,$opt_p);
35 &do_check
(split(":",$opt_l));
39 (my $checkip, my $checkport,my $routername) = @_;
40 # as socksports may not be published (therefore "0") here,
41 # let's try 9050, the default port:
42 if ($checkport == 0) { $checkport = 9050; }
43 # print "Checking $checkip:$checkport\n";
44 my $s5socket = IO
::Socket
::INET
->new(PeerAddr
=> $checkip,
45 PeerPort
=> $checkport, Proto
=> "tcp", Type
=> SOCK_STREAM
,
49 print $s5socket pack("CCC",'5','1','0');
51 local $SIG{ALRM
} = sub { die "alarm\n" };
53 read ($s5socket,$got[0],1);
54 read ($s5socket,$got[1],1);
58 return; # die unless $@ eq "alarm\n";
60 if ($got[0] eq pack('C','5')) {
61 if(defined($routername)) {
62 print "Found SOCKS5 at $routername ($checkip:$checkport)\n";
64 print "Found SOCKS5 at $checkip:$checkport\n";
67 if(defined($routername)) {
68 print "$routername ($checkip:$checkport) answers - " .
71 print "$checkip:$checkport answers - but not SOCKS5.\n";
75 if(defined($routername)) {
76 print STDERR
"Can't connect to $routername " .
77 "($checkip:$checkport) ($!)\n";
79 print STDERR
"Can't connect to $checkip:$checkport ($!)\n";