View Single Post
Old 2nd February 2016
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,503
Default

With the following modifications the script exits with error code 4, when the IP is listed:
Code:
     56 EXITCODE=0      # assume no listing 
     57
     58 # -- cycle through all the blacklists
     59 for BL in ${BLISTS} ; do
     60
     61     # print the UTC date (withour linefeed)
     62     printf $(env TZ=UTC date "+%Y-%m-%d_%H:%M:%S_%Z")
     63
     64     # show the reversed IP and append the name of the blacklist
     65     printf "%-40s" " ${reverse}.${BL}."
     66
     67     # use dig to lookup the name in the blacklist
     68     #echo "$(dig +short -t a ${reverse}.${BL}. |  tr '\n' ' ')"
     69     LISTED="$(dig +short -t a ${reverse}.${BL}.)"
     70     echo [${LISTED:-OK}]
     71     # set exit code when answer contains '127.'
     72     echo $LISTED | grep '127\.' >/dev/null  &&  EXITCODE=4
     73 done
     74
     75 exit $EXITCODE
Example run:
Code:
$ blcheck 114.97.100.118 ; echo Errorcode: [$?]
IP 114.97.100.118 NAME ---
2016-02-02_03:22:40_UTC 118.100.97.114.cbl.abuseat.org.        [127.0.0.2]
2016-02-02_03:22:40_UTC 118.100.97.114.dnsbl.sorbs.net.        [OK]
2016-02-02_03:22:40_UTC 118.100.97.114.bl.spamcop.net.         [OK]
2016-02-02_03:22:40_UTC 118.100.97.114.zen.spamhaus.org.       [127.0.0.11 127.0.0.4]
Errorcode: [4]

$ blcheck 1.2.3.4 ; echo Errorcode: [$?]        
IP 1.2.3.4 NAME ---
2016-02-02_03:24:38_UTC 4.3.2.1.cbl.abuseat.org.               [OK]
2016-02-02_03:24:38_UTC 4.3.2.1.dnsbl.sorbs.net.               [OK]
2016-02-02_03:24:38_UTC 4.3.2.1.bl.spamcop.net.                [OK]
2016-02-02_03:24:38_UTC 4.3.2.1.zen.spamhaus.org.              [OK]
Errorcode: [0]
Attached Files
File Type: sh blcheck.sh (2.3 KB, 192 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote