Getting a List of Tor server Nodes in perl
In 2008, I wrote a module in perl called Net::Tor::servers (which can be found in CPAN). Below is the code (albeit not as complicated as the module) which will get a list of Tor servers into an array called @torarray.
One use of this module is a script I wrote which adds all the Tor servers into an IP blacklist on Smoothwall firewalls. I used to run the community version at home last year but got rid of it when the box died.
The script can be found here:
http://www.cpan.org/modules/by-authors/id/A/AJ/AJDIXON/torblacklister.pl
The code is thus:
#/usr/bin/perl
use LWP::Simple
my @torarray=();
my @arrayrecord=();
my $router;
my @rarray;
my $torserver = "128.31.0.34";
my $port = 9031;
my $content = get("http://$torserver:$port/tor/status/all");
my @lines = split(/\n/,$content);
foreach $router (@lines) {
@rarray = split(/\ /,$router);
if($rarray[0] =~ /^r$/) {
my $ip=$rarray[6];
my $hostname=$rarray[1];
my $orport = $rarray[7];
my $dirrepport = $rarray[8];
@torarray = (@torarray,[$ip,$hostname,$orport,$dirrepport]);
}
}
Updated: oops, forgot the use clause…