On Thu, 30 May 2013, Alex wrote:

Hi all,

I'd like to be able to take a domain such as fellass.us and check it
against the same blacklists used by sites like mxtools, except do it
on the command-line. We have our own URIBL for domains that haven't
yet been added to zen or surriel, etc. I'd like to periodically check
my list against theirs to see if it's been added, and whether I should
remove the domain from my list.

I know I can run something like the following for surbl:

# host fellass.us.multi.surbl.org
fellass.us.multi.surbl.org has address 127.0.0.64

It would be great if there was an automated script that included
checking surbl.org and others right from a shell script, given a
domain name.

Thanks,
Alex

Alex,
I've attached a perl script that I hacked together 15 years ago to
query both host-based and IPv4 based DNSBL lists. It's kind'a mutated
over the years (entries added/removed and more features added).
Probably needs even more updating, haven't checked the RBL list
in a while.
It will read arguments from the command line, from std-in or from
a file of names.

It was written before IPv6, so has no provision for IPv6 addrs.

Feel free to (ab)use as you see fit.


--
Dave Funk                                  University of Iowa
<dbfunk (at) engineering.uiowa.edu>        College of Engineering
319/335-5751   FAX: 319/384-0549           1256 Seamans Center
Sys_admin/Postmaster/cell_admin            Iowa City, IA 52242-1527
#include <std_disclaimer.h>
Better is not better, 'standard' is better. B{
#!/usr/bin/perl

#
# Modify to take domain-names to feed to s[ac].subr.org
#
require 5.002;
use Getopt::Std;
use IO::Socket;

my($debug,$verbose,$clean,$from_file,$check_ws,$dirty,$hname);
#
$FALSE = 0;
$TRUE = 1;

#
# Subroutine to check to see if its argument is a valid
# Octet for an IP address
#
sub check_octet ($) {
my($octet); $octet= $_[0];
if ($octet =~ m/[^0-9]/ ) {
    print STDERR "ERROR: invalid IP address part $octet\n";
    exit;
}
if (($octet < 0) or ($octet > 255)) {
    print STDERR "ERROR: invalid IP address part $octet\n";
    exit;
}
}
#endsub check_octet

#
# subroutine to run IP address based checks.
# input args (ipaddr, ipreverse)
#               ipaddr = IPv4 address in forward format
#               ipreverse = IPv4 address in reverse format
#
sub check_IP {
  my ( $ipaddr, $ipreverse ) = @_;

#$hname= gethostbyname("$ipreverse.rbl.maps.vix.com.");
#
if ($debug) {print "trying rbl-plus.mail-abuse.org\n";}
$hname= gethostbyname("$ipreverse.rbl-plus.mail-abuse.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from RBL-Plus";
   print " rbl-plus.mail-abuse.org" unless not $verbose;
   print "\n"
}

# Get all these now with our access to RBL-Plus
#$hname= gethostbyname("$ipreverse.blackholes.mail-abuse.org.");
#   print "host $ipaddr resolves to $hname from RBL\n";
#}
#
#$hname= gethostbyname("$ipreverse.dialups.mail-abuse.org.");
#   print "host $ipaddr resolves to $hname from DUL\n";
#
#$hname= gethostbyname("$ipreverse.relays.mail-abuse.org.");
#   print "host $ipaddr resolves to $hname from RSS\n";
#
#if ($debug) {print "trying orbs.gst-group.co.uk\n";}
#$hname= gethostbyname("$ipreverse.orbs.gst-group.co.uk.");
#}
#if ($debug) {print "trying manual.orbs.gst-group.co.uk\n";}
#$hname= gethostbyname("$ipreverse.manual.orbs.gst-group.co.uk.");
#}

# these guys took themselves out after 9/11/01 attack
#$hname= gethostbyname("$ipreverse.or.orbl.org.");
#   print "host $ipaddr resolves to $hname from ORBL.org\n";
#}

# another one bites the dust, RIP 12/31/2006
#if ($debug) {print "trying relays.ordb.org\n";}
#$hname= gethostbyname("$ipreverse.relays.ordb.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from ORDB.org\n";
#}

# 'dsbl.org' is the replacement for orbz.org
# 'dsbl.org' RIP 9/24/08
#
#if ($debug) {print "trying list.dsbl.org\n";}
#$hname= gethostbyname("$ipreverse.list.dsbl.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from list.dsbl.org\n";
#}
#
#if ($debug) {print "trying unconfirmed.dsbl.org\n";}
#$hname= gethostbyname("$ipreverse.unconfirmed.dsbl.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from unconfirmed.dsbl.org\n";
#}

if ($debug) {print "trying bl.spamcop.net\n";}
$hname= gethostbyname("$ipreverse.bl.spamcop.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from bl.spamcop.net\n";
}

# ORBZ, RIP 3/25/2002 (died from a shot by a lawyer)
#if ($debug) {print "trying inputs.orbz.org\n";}
#$hname= gethostbyname("$ipreverse.inputs.orbz.org.");
#   print "host $ipaddr resolves to $hname from inputs.ORBZ.org\n";
#}
#
#if ($debug) {print "trying outputs.orbz.org\n";}
#$hname= gethostbyname("$ipreverse.outputs.orbz.org.");
#   print "host $ipaddr resolves to $hname from outputs.ORBZ.org\n";
#}

# Shit, another one wiped out. Killed by DDOS (RIP, 9/15/03)
#if ($debug) {print "trying orbs.dorkslayers.com\n";}
#$hname= gethostbyname("$ipreverse.orbs.dorkslayers.com.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from orbs.dorkslayers.com\n";
#}

# These guys seem to quit responding (9/20/03)
#
#if ($debug) {print "trying proxies.relays.monkeys.com\n";}
#$hname= gethostbyname("$ipreverse.proxies.relays.monkeys.com.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from proxies.relays.monkeys.com\n";
#}

# Yet anoter RBL bites the dust. Killed by DDOS (RIP 8/20/2003)
# it came back. Not really, reports hits on -all- addresses
#if ($debug) {print "trying relays.osirusoft.com\n";}
#$hname= gethostbyname("$ipreverse.relays.osirusoft.com.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from relays.osirusoft.com\n";
#}

## if ($debug) {print "trying sbl.spamhaus.org\n";}
## $hname= gethostbyname("$ipreverse.sbl.spamhaus.org.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
##    print "host $ipaddr resolves to $aname from sbl.spamhaus.org\n";
## }
## # 11/27/06
## if ($debug) {print "trying zen.spamhaus.org\n";}
## $hname= gethostbyname("$ipreverse.zen.spamhaus.org.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
##    print "host $ipaddr resolves to $aname from zen.spamhaus.org\n";
## }
## 
## if ($debug) {print "trying xbl.spamhaus.org\n";}
## $hname= gethostbyname("$ipreverse.xbl.spamhaus.org.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
##    print "host $ipaddr resolves to $aname from xbl.spamhaus.org\n";
## }

# These guys quit responding on 4/4/04
#if ($debug) {print "trying spamsites.bl.reynolds.net.au\n";}
#$hname= gethostbyname("$ipreverse.spamsites.bl.reynolds.net.au.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from spamsites.bl.reynolds.net.au\n";
#}
#
#if ($debug) {print "trying spews.bl.reynolds.net.au\n";}
#$hname= gethostbyname("$ipreverse.spews.bl.reynolds.net.au.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from spews.bl.reynolds.net.au\n";
#}

# easynet.nl DSBL went offline 12/01/03, tired.
#if ($debug) {print "trying blackholes.easynet.nl\n";}
#$hname= gethostbyname("$ipreverse.blackholes.easynet.nl.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from blackholes.easynet.nl\n";
#}
#
#if ($debug) {print "trying dynablock.easynet.nl\n";}
#$hname= gethostbyname("$ipreverse.dynablock.easynet.nl.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from dynablock.easynet.nl\n";
#}
#
# quit resonding
#if ($debug) {print "trying dnsbl.njabl.org\n";}
#$hname= gethostbyname("$ipreverse.dnsbl.njabl.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from dnsbl.njabl.org\n";
#}

# this is timing-out 3/11/08
# if ($debug) {print "trying dynablock.njabl.org\n";}
# $hname= gethostbyname("$ipreverse.dynablock.njabl.org.");
# if (length $hname > 0) {
#    $aname= inet_ntoa($hname);
#    print "host $ipaddr resolves to $aname from dynablock.njabl.org\n";
# }

# see http://www.us.sorbs.net/using.shtml
if ($debug) {print "trying dnsbl.sorbs.net\n";}
$hname= gethostbyname("$ipreverse.dnsbl.sorbs.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from dnsbl.sorbs.net\n";
}

if ($debug) {print "trying rhsbl.sorbs.net\n";}
$hname= gethostbyname("$ipreverse.rhsbl.sorbs.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from rhsbl.sorbs.net\n";
}

if ($debug) {print "trying l1.spews.dnsbl.sorbs.net\n";}
$hname= gethostbyname("$ipreverse.l1.spews.dnsbl.sorbs.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from l1.spews.dnsbl.sorbs.net\n";
}

# added 7/31/06
if ($debug) {print "trying l2.spews.dnsbl.sorbs.net\n";}
$hname= gethostbyname("$ipreverse.l2.spews.dnsbl.sorbs.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from l2.spews.dnsbl.sorbs.net\n";
}

if ($debug) {print "trying cbl.abuseat.org\n";}
$hname= gethostbyname("$ipreverse.cbl.abuseat.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from cbl.abuseat.org\n";
}

# quit responding 12/12/04
#if ($debug) {print "trying relays.visi.com\n";}
#$hname= gethostbyname("$ipreverse.relays.visi.com.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from relays.visi.com\n";
#}

## added 11/14/03; skip for now, seem to be off air 5/14/09
#if ($debug) {print "trying blacklist.spambag.org\n";}
#$hname= gethostbyname("$ipreverse.blacklist.spambag.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from blacklist.spambag.org\n";
#}

# added 01/14/04
if ($debug) {print "trying hil.habeas.com\n";}
$hname= gethostbyname("$ipreverse.hil.habeas.com.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from hil.habeas.com\n";
}

# added 02/13/07
if ($debug) {print "trying sa-accredit.habeas.com\n";}
$hname= gethostbyname("$ipreverse.sa-accredit.habeas.com.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from sa-accredit.habeas.com\n";
}

# added 04/02/08
if ($debug) {print "trying ips.backscatterer.org\n";}
$hname= gethostbyname("$ipreverse.ips.backscatterer.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from ips.backscatterer.org\n";
}

# added 04/02/08
if ($debug) {print "trying dnsbl-1.uceprotect.net\n";}
$hname= gethostbyname("$ipreverse.dnsbl-1.uceprotect.net.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from dnsbl-1.uceprotect.net\n";
}

# ## added 04/12/04
# #if ($debug) {print "trying sc.surbl.org\n";}
# #$hname= gethostbyname("$ipreverse.sc.surbl.org.");
# #if (length $hname > 0) {
# #   $aname= inet_ntoa($hname);
# #   print "host $ipaddr resolves to $aname from sc.surbl.org\n";
# #}
# #
# ## added 04/12/04
# #if ($debug) {print "trying ws.surbl.org\n";}
# #$hname= gethostbyname("$ipreverse.ws.surbl.org.");
# #if (length $hname > 0) {
# #   $aname= inet_ntoa($hname);
# #   print "host $ipaddr resolves to $aname from ws.surbl.org\n";
# #}
# ## added 04/26/04
# #if ($debug) {print "trying be.surbl.org\n";}
# #$hname= gethostbyname("$ipreverse.be.surbl.org.");
# #if (length $hname > 0) {
# #   $aname= inet_ntoa($hname);
# #   print "host $ipaddr resolves to $aname from be.surbl.org\n";
# #}
# ## added 06/17/04
# #if ($debug) {print "trying ob.surbl.org\n";}
# #$hname= gethostbyname("$ipreverse.ob.surbl.org.");
# #if (length $hname > 0) {
# #   $aname= inet_ntoa($hname);
# #   print "host $ipaddr resolves to $aname from ob.surbl.org\n";
# #}
# #$myaddr=$ipaddr;
# ## added 06/25/04
# #    if ($debug) {print "trying multi.surbl.org\n";}
# #    $hname= gethostbyname("$ipreverse.multi.surbl.org.");
# #    if (length $hname > 0) {
# #       $aname= inet_ntoa($hname);
# #       print "host $myaddr resolves to $aname from multi.surbl.org\n";
# #    }
# ## added 06/25/04
# #    if ($debug) {print "trying ds.surbl.org\n";}
# #    $hname= gethostbyname("$ipreverse.ds.surbl.org.");
# #    if (length $hname > 0) {
# #       $aname= inet_ntoa($hname);
# #       print "host $myaddr resolves to $aname from ds.surbl.org\n";
# #    }
# ## added 06/25/04
# #    if ($debug) {print "trying ab.surbl.org\n";}
# #    $hname= gethostbyname("$ipreverse.ab.surbl.org.");
# #    if (length $hname > 0) {
# #       $aname= inet_ntoa($hname);
# #       print "host $myaddr resolves to $aname from ab.surbl.org\n";
# #    }

## temporarily take out, seems to be slow (9/7/07)
## # added 08/25/04 see http://www.senderdb.com/lookup/dns.htm
##     if ($debug) {print "trying pub.senderdb.net\n";}
##     $hname= gethostbyname("$ipreverse.pub.senderdb.net.");
##     if (length $hname > 0) {
##        $aname= inet_ntoa($hname);
##        print "host $myaddr resolves to $aname from pub.senderdb.net\n";
##     }

# added 10/31/05 see http://www.heise.de/ix/nixspam/dnsbl_en/
    if ($debug) {print "trying ix.dnsbl.manitu.net\n";}
    $hname= gethostbyname("$part4.$part3.$part2.$ix.dnsbl.manitu.net.");
    if (length $hname > 0) {
       $aname= inet_ntoa($hname);
       print "host $ipaddr resolves to $aname from ix.dnsbl.manitu.net\n";
    }

## added 06/13/05 see http://www.JAMMConsulting.com/jamm/dnsbl.jsp
## dead, reports hits on all addresses (9/12/09)
#    if ($debug) {print "trying dnsbl.JAMMConsulting.com\n";}
#    $hname= gethostbyname("$ipreverse.dnsbl.JAMMConsulting.com.");
#    if (length $hname > 0) {
#       $aname= inet_ntoa($hname);
#       print "host $ipaddr resolves to $aname from dnsbl.JAMMConsulting.com\n";
#    }


# Barracuda RBL list, added 3/31/09
if ($debug) {print "trying b.barracudacentral.org\n";}
$hname= gethostbyname("$ipreverse.b.barracudacentral.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from b.barracudacentral.org\n";
}

# Marc Perkel's HostKarma list, added 4/6/09
if ($debug) {print "trying hostkarma.junkemailfilter.com\n";}
$hname= gethostbyname("$ipreverse.hostkarma.junkemailfilter.com.");
if (length $hname > 0) {
   ($a,$b,$nxt8,$last8) = unpack ('C4',$hname);
   if ($nxt8 != 0) {
        $hname= gethostbyname("$ipreverse.hostkarma.junkemailfilter.com.");
        ($a,$b,$nxt8,$last8) = unpack ('C4',$hname);
   }
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from hostkarma.junkemailfilter.com\n";
   print "host $ipaddr in whitelist from hostkarma\n" if ($last8 == 1);
   print "host $ipaddr in blacklist from hostkarma\n" if ($last8 == 2);
   print "host $ipaddr in yellowlist from hostkarma\n" if ($last8 == 3);
   print "host $ipaddr in brownlist from hostkarma\n" if ($last8 == 4);
   print "host $ipaddr in NO-BLock from hostkarma\n" if ($last8 == 5);
}

# spamcannibal.org list, added 6/24/09
if ($debug) {print "trying bl.spamcannibal.org\n";}
$hname= gethostbyname("$ipreverse.bl.spamcannibal.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
   print "host $ipaddr resolves to $aname from bl.spamcannibal.org\n";
}

# added 12/14/03 (removed 01/15/04)
#if ($debug) {print "trying bl.blueshore.net\n";}
#$hname= gethostbyname("$ipreverse.bl.blueshore.net.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#   print "host $ipaddr resolves to $aname from bl.blueshore.net\n";
#}

## opm.blitzed.org quit responding 5/30/07, remove for time being
## if ($debug) {print "trying opm.blitzed.org (www.blitzed.org/opm)\n";}
## $hname= gethostbyname("$ipreverse.opm.blitzed.org.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
## #   if ($aname != "64.211.252.76") {
##        print "host $ipaddr resolves to $aname from opm.blitzed.org\n";
## #   }
## }

## # added 7/26/06 abandoned 6/30/07
## if ($debug) {printf "trying dnsbl.tqmcube.com 
(www.tqmcube.com/mserver.php)\n";}
## $hname= gethostbyname("$ipreverse.dnsbl.tqmcube.com.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
## #   if ($aname != "64.211.252.76") {
##        printf "host $ipaddr resolves to $aname from dnsbl.tqmcube.com\n";
## #   }
## }

# added 7/31/06
if ($debug) {printf "trying dnsbl.ahbl.org\n";}
$hname= gethostbyname("$ipreverse.dnsbl.ahbl.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
#   if ($aname != "64.211.252.76") {
       printf "host $ipaddr resolves to $aname from dnsbl.ahbl.org\n";
#   }
}
# added 9/5/06 http://www.blars.org/errors/block.html
# dead 9/12/09
#if ($debug) {printf "trying block.blars.org\n";}
#$hname= gethostbyname("$ipreverse.block.blars.org.");
#if (length $hname > 0) {
#   $aname= inet_ntoa($hname);
#       printf "host $ipaddr resolves to $aname from block.blars.org\n";
#}
## temporarily take out, slow today (9/7/07)
## # added 10/23/06     see: http://www.msrbl.com/site/
## if ($debug) {printf "trying rbl.msrbl.net\n";}
## $hname= gethostbyname("$ipreverse.combined.rbl.msrbl.net.");
## if (length $hname > 0) {
##    $aname= inet_ntoa($hname);
##        printf "host $ipaddr resolves to $aname from 
combined.rbl.msrbl.net\n";
## }
# added 5/7/07          see: http://www.dnswl.org/tech
if ($debug) {printf "trying list.dnswl.org\n";}
$hname= gethostbyname("$ipreverse.list.dnswl.org.");
if (length $hname > 0) {
   $aname= inet_ntoa($hname);
       printf "host $ipaddr resolves to $aname from list.dnswl.org\n";
}

# ORBS, RIP 6/3/2001
#
#$hname= gethostbyname("$ipreverse.inputs.orbs.org.");
#   print "host $ipaddr resolves to $hname from Inputs-ORBS\n";
#
#$hname= gethostbyname("$ipreverse.outputs.orbs.org.");
#   print "host $ipaddr resolves to $hname from Outputs-ORBS\n";
#
#$hname= gethostbyname("$ipreverse.spamsources.orbs.org.");
#   print "host $ipaddr resolves to $hname from SpamSources-ORBS\n";
#
#$hname= gethostbyname("$ipreverse.manual.orbs.org.");
#   print "host $ipaddr resolves to $hname from ManualBlock-ORBS\n";

}
#endsub check_IP

##########################################################################
# subroutine to check names, calls check_IP if IP-adder
# input args (hostname, myaddr)
#   if checking a host/domain name, myaddr == hostname == name to check
#   if checking a ipv4 address:
#               hostname = IPv4 address in forward format
#               myaddr = IPv4 address in reverse format
#
sub check_NAME {
  my ( $hostname, $myaddr ) = @_;
  my($in_ws,$last8);
  $in_ws= 0;

## # added 04/12/04
##   if ($debug) {print "trying $myaddr.sc.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.sc.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from sc.surbl.org\n";
##   }
## # added 04/20/04
##   if ($debug) {print "trying $myaddr.ws.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.ws.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from ws.surbl.org\n";
##      $in_ws= 1;
##   }
## # added 04/20/04
##   if ($debug) {print "trying $myaddr.be.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.be.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from be.surbl.org\n";
##   }
## # added 06/17/04
##   if ($debug) {print "trying $myaddr.ob.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.ob.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from ob.surbl.org\n";
##   }
## # added 06/17/04
##   if ($debug) {print "trying $myaddr.ab.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.ab.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from ab.surbl.org\n";
##   }
## # added 06/29/04
##   if ($debug) {print "trying $myaddr.ds.surbl.org\n";}
##   $hname= gethostbyname("$myaddr.ds.surbl.org.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from ds.surbl.org\n";
##   }
# added 06/25/04
  if ($debug) {print "trying $myaddr.multi.surbl.org\n";}
  $hname= gethostbyname("$myaddr.multi.surbl.org.");
  if (length $hname > 0) {
     ($a,$b,$c,$last8) = unpack ('C4',$hname);
     print "host $hostname in SC from multi.surbl.org\n" if ($last8 & 2);
     if ($last8 & 4) {
          if ( !$in_ws) {print "host $hostname in WS from multi.surbl.org\n";}
          $in_ws= 1;
     }
     print "host $hostname in Phish from multi.surbl.org\n" if ($last8 & 8);
     print "host $hostname in OB from multi.surbl.org\n" if ($last8 & 16);
     print "host $hostname in AB from multi.surbl.org\n" if ($last8 & 32);
     print "host $hostname in JP from multi.surbl.org\n" if ($last8 & 64);
     print "host $hostname in 128 from multi.surbl.org\n" if ($last8 & 128);
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from multi.surbl.org\n";
  }
# added 06/29/08
  if ($debug) {print "trying $myaddr.xs.surbl.org\n";}
  $hname= gethostbyname("$myaddr.xs.surbl.org.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from xs.surbl.org\n";
  }
# added 01/04/06
  if ($debug) {print "trying $myaddr.black.uribl.com\n";}
  $hname= gethostbyname("$myaddr.black.uribl.com.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from black.uribl.com\n";
  }
  if ($debug) {print "trying $myaddr.grey.uribl.com\n";}
  $hname= gethostbyname("$myaddr.grey.uribl.com.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from grey.uribl.com\n";
  }
  if ($debug) {print "trying $myaddr.multi.uribl.com\n";}
  $hname= gethostbyname("$myaddr.multi.uribl.com.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from multi.uribl.com\n";
  }
# added 01/26/06
  if ($debug) {print "trying $myaddr.spam.uri.intershop.de\n";}
  $hname= gethostbyname("$myaddr.spam.uri.intershop.de.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from spam.uri.intershop.de\n";
  }
# added 10/23/06
  if ($debug) {print "trying $myaddr.rhsbl.ahbl.org\n";}
  $hname= gethostbyname("$myaddr.rhsbl.ahbl.org.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from rhsbl.ahbl.org\n";
  }
## # added 07/08/09
## removed 07/30/09 (too many timeouts)
##   if ($debug) {print "trying $myaddr.uribl.swinog.ch\n";}
##   $hname= gethostbyname("$myaddr.uribl.swinog.ch.");
##   if (length $hname > 0) {
##      $aname= inet_ntoa($hname);
##      print "host $hostname resolves to $aname from uribl.swinog.ch\n";
##   }
# added 07/23/09
  if ($debug) {print "trying $myaddr.url.rbl.jp\n";}
  $hname= gethostbyname("$myaddr.url.rbl.jp.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from url.rbl.jp\n";
  }
## added 07/23/09; removed 12/13/10, seems dead returns garbage on any query
#  if ($debug) {print "trying $myaddr.block.rhs.mailpolice.com\n";}
#  $hname= gethostbyname("$myaddr.block.rhs.mailpolice.com.");
#  if (length $hname > 0) {
#     $aname= inet_ntoa($hname);
#     print "host $hostname resolves to $aname from block.rhs.mailpolice.com\n";
#  }
# added 12/13/10
  if ($debug) {print "trying $myaddr.truncate.gbudb.net\n";}
  $hname= gethostbyname("$myaddr.truncate.gbudb.net.");
  if (length $hname > 0) {
     $aname= inet_ntoa($hname);
     print "host $hostname resolves to $aname from truncate.gbudb.net\n";
  }
}
#endsub check_NAME

sub check_OBJ ($) {
my($myaddr); $myaddr= $_[0];
my($in_ws,$last8);
my($part1,$part2,$part3,$part4,$rest);
  $in_ws= 0;

  if ($myaddr !~ /[\-a-z_]/i) { # not domain name, assume IPv4 addr

    ($part1,$part2,$part3,$part4,$rest) = split /\./, $myaddr, 5;

    if ((length $part4 < 1) or (length $rest > 0)) {
        print STDERR "ERROR: invalid IP address $myaddr\n";
        exit;
    }

    check_octet($part1);
    check_octet($part2);
    check_octet($part3);
    check_octet($part4);
    $rest= $part4 . "." . $part3 . "." . $part2 . "." . $part1;

    if ($debug) {print "Good IP address $myaddr $rest\n";}

    check_IP($myaddr,$rest);    # do IPv4 bl checks
    check_NAME($myaddr,$rest);  # tread IPv4 addr as name, do name checks

  } else {      # its domain name, do name-based checks
    check_NAME($myaddr,$myaddr);
  }
}
#endsub check_OBJ
#===================================================================
# Main
#
# look for opts '-d' == debug
# -v == verbose
# -c == clean
# -f == read from file
#
    getopts('cdfv');
    $verbose= $opt_v;
    $debug= $opt_d;
    $clean= $opt_c;
    $from_file= $opt_f;
#
#die "Missing address argument" if (@ARGV != 1);

my($i,$checkname);

if ($from_file) {
  die "Missing input file" if (@ARGV != 1);
  open IN, "< $ARGV[0]"
    or die "could not read file: $ARGV[0] ($!)\n";
  while (<>) {
    $checkname= $_;
    chomp $checkname;
    if ($checkname =~ /^#/ ) {
      next;
    };
    check_OBJ($checkname);
  };
  close(IN);
  exit;
}

if (defined( $ARGV[0]) ) {
  while ( $checkname = shift @ARGV  ) {
        chomp $checkname;
        check_OBJ($checkname);
  };
} else {
  while (<>) {
    $checkname= $_;
    chomp $checkname;
    if ($checkname =~ /^#/ ) {
        next;
    };
    check_OBJ($checkname);
  };
};


Reply via email to