[Mimedefang] Command line RBL checkers

Michael Lambert lambert at jeol.com
Wed Sep 10 10:41:09 EDT 2008


WBrown at e1b.org wrote:
> Does anyone know of an command line DNSRBL checker?  I used to use
> DNSStuff.com, but they went pay-only a while ago.
> http://www.moensted.dk/spam/ isn't bad, just a little hard on the eyes.
> 
> Is there a command line checker out there that would take an IP, reformat
> it to each lookup and then submit the DNS query?

I wrote this script on freebsd several years ago.  Beware wrapped lines...


cage# cat /usr/local/bin/blc
#!/bin/sh

BLACKLISTS=/usr/local/etc/anti-spam/dnsblsites

if [ $# -ne 1 ]; then
        echo "Usage: dnsbl <ip address|host name>"; exit 1
fi

echo $1|egrep '^[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]$' >/dev/null 2>&1
if [ $? -eq 0 ]; then
        IP=$1
else
        host -t a $1
        IP=`host -t a $1 2>/dev/null|grep "has address"|cut -d" " -f4`
        echo $IP | egrep '^[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]$' >/dev/null 2>&1
        if [ $? -eq 1 ]; then
                echo "host lookup failed"
                exit 1
        fi
fi

echo "Checking ${IP}..."
set -- $(IFS=.;echo ${IP})
for blacklist in `egrep -v '(^#|^$)' $BLACKLISTS`
do
        echo -n "${blacklist}: "
        lookup="`host -t a $4.$3.$2.$1.${blacklist} 2>&1`"
        return_code=$?
        case $return_code in
                0) status="Listed - `echo $lookup|awk '{print $NF}'`";;
                1) status="" ;;
                *) status="ERROR";;
        esac
        echo $status
done


Add/remove DNSBLs as desired...

cage# cat /usr/local/etc/anti-spam/dnsblsites
sbl.spamhaus.org
pbl.spamhaus.org
xbl.spamhaus.org
zen.spamhaus.org
cbl.abuseat.org
dnsbl.njabl.org
list.dsbl.org
dnsbl.sorbs.net
safe.dnsbl.sorbs.net
l1.spews.dnsbl.sorbs.net
dnsbl.ahbl.org
blackholes.five-ten-sg.com
bl.spamcop.net


-- 
Michael Lambert
Systems Admin, IT Dept
JEOL USA Inc
http://www.jeolusa.com/



More information about the MIMEDefang mailing list