#!/usr/bin/env perl
use 5.14.0;
use strict;
use warnings;
use Net::DNS;
if ($ENV{QUERY_STRING} eq "viewsource") {
print "Content-Type: text/plain\n\n";
open(my $fh, "<", $0);
while (<$fh>) {
print;
}
close($fh);
exit(0);
}
say "Content-Type: text/html\n\n";
say "
Tor Exit Node Test
\n\n";
sub reverse_ip {
my $ip = shift;
my @o = split(/\./, $ip, 4);
return join(".", reverse(@o));
}
my $dns = join(".",
reverse_ip($ENV{REMOTE_ADDR}),
$ENV{SERVER_PORT},
reverse_ip($ENV{SERVER_ADDR}),
"ip-port.exitlist.torproject.org",
);
say "Your apparent IP: $ENV{REMOTE_ADDR}
";
say "The server's IP: $ENV{SERVER_ADDR}
port $ENV{SERVER_PORT}
";
say "DNS hostname to check Tor exit node: $dns
";
my $res = Net::DNS::Resolver->new;
my $query = $res->search($dns);
my $is_tor = 0;
if ($query) {
foreach my $rr ($query->answer) {
next unless $rr->type eq 'A';
say "DNS answered with: IN A " . $rr->address . "
";
if ($rr->address eq '127.0.0.2') {
$is_tor = 1;
}
}
} else {
say "DNS query failed with: " . $res->errorstring . "
";
}
if ($is_tor) {
say "You are using Tor.
";
} else {
say "You do not appear to be using Tor.
";
}
say "Source code
";
say "";