spf-discuss
[Top] [All Lists]

new SPF email checker utility

2004-07-12 21:47:02
Hi,

I've cobbled together a script which performs SPF, CallerID, and RBL
checks on emails, and put it up on a spare domain I own on my home DSL
connection.

Compose any email and send it to 
test(_at_)yahoo(_dot_)com(_dot_)spfchk(_dot_)senderpays(_dot_)com
to perform a test and get back some instructions.

The reason for the curious recipient address is that I plan to also
add some checks for a complete email "chain" later on (so I can check
not just that your sending SPF stuff is working properly, but also
work out if your proposed recipient is probably going to block you or
not as well - and maybe also something to let you know whether you'd
end up blocking replies from them too...).

On my to-do list:
1. Bigger list of RBL checks (if you want to help, just add to my code
   snippet below)
2. add the spamassassin score into the output
3. format the reply so it's...
   A) Pretty.
   B) Doesn't get blocked by spamassassin etc

All comments, suggestions, and code-donations (perl please) accepted.
   
Kind Regards,
Chris Drake



#######################################################################

=head2 blacklisted

return the RBL blacklisting status of an IP address

B<Input Paramaters>

        $addr    - IP to check
        $details - 0 to return just a 1 if blacklisted
                 - 1 to return all blacklisting results

B<Output>

        list (a,b) returned
        a = 1 if blacklisted
        b = text string of blacklisting results

  print "\nin_black=" . join("\n", &blacklisted($ARGV[0],'rblchk:') );

=cut
#######################################################################
sub blacklisted {
my ($addr,$details) = @_;
my ($ret,$listed);
my %blacklists=('blackholes.mail-abuse.org'=> '^127\.0\.0\.',
                'relays.visi.com'       => '^127\.0\.0\.2$',
                'dnsbl.njabl.org'       => '^127\.0\.0\.[24589]$',
                'dialups.mail-abuse.org'=> '^127\.0\.0\.',
                'list.dsbl.org'         => '^127\.0\.0\.2$',
                'dnsbl.njabl.org'       => '^127\.0\.0\.',
                'relays.ordb.org'       => '^127\.0\.0\.2$',
                'relays.mail-abuse.org' => '^127\.0\.0\.',
                'dnsbl.njabl.org'       => '^127\.0\.0\.3$',
#               'relays.osirusoft.com'  => '^127\.0\.0\.',
                'unconfirmed.dsbl.org'  => '^127\.0\.0\.2$');

  foreach my $srv (keys %blacklists) {
    my $check = join(".", reverse(split(/\./, $addr))) .".". $srv;
    my $start=time;
    my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($check);
    $start = time - $start;
    $ret.=$details . ' ' . $addr . ' ' . $srv . "(${start}s)\t";
    if(@addrs) {
      my $result = inet_ntoa($addrs[0]);
      if ($result =~ $blacklists{$srv}) {
        $ret.="Listed ($result)";
        $listed=1;
        return ($listed,1) if(!$details);
      } else {
        $ret.="Not listed ($result)";
      }
    } else {
      $ret.='Not listed';
    }
    $ret .= "\n";       
  }
  return ($listed,$ret);
}