#!/usr/bin/perl -w use strict; # first (and only) argument should be a port number to look for my $testPort = $ARGV[0] || die "Usage: tor-exitpoint \n"; # fetch tor server list from server, cache locally to be nice... my $cache = ".tor-policies"; my $cacheExpiration = 60*60; if((! -f $cache) || (stat($cache))[9] + $cacheExpiration < time()) { print "Fetching aggregate tor policy file.\n"; system "wget -q http://tor.noreply.org:9030/ -O - > $cache"; } # parse rules for each server.. my $routerName; my $routerIP; my $findPort = 0; open(TOR,$cache) || die "can't open cache file: $!"; while() { chomp; if(m#^router\s+(.*)\s+(\d+\.\d+\.\d+\.\d+)#) { # found router list $routerName = $1; $routerIP = $2; $findPort = 1; } elsif($findPort && m#^(reject|accept)\s+\*:(\d+|\*)-?(\d+)?# ) { my $type = $1; my $startport = $2; my $endport = $3 || $2; if($startport eq "*" || ( $startport <= $testPort && $endport >= $testPort )) { print "$routerName ($routerIP) " . $type . "s $testPort ($_)\n"; $findPort = 0; } } } close(TOR);