This script checks your IP address against a list of RBL servers and send an email if a match is found.
nano /root/blacklistcheck
copy, paste & edit email, from and hosts
Shell-Script
- #!/bin/bash
- if
- [ -f /root/mailqsend ] ; then
- EMAIL="toYour@email.com"
- WARNING="Host1 Blacklisted - please check"
- echo "Host1 blacklisted check the mailsystem" | mail -a "From: postmaster@myhost.com" $EMAIL -s "$WARNING"
- rm /root/mailqsend
- fi
- # IPs or hostnames to check if none provided as arguments to the script
- hosts='
- 103.207.236.190
- '
- # Locally maintained list of DNSBLs to check
- LocalList='
- bl.score.senderscore.com
- b.barracudacentral.org
- bl.spamcannibal.org
- bl.spamcop.net
- dnsbl.sorbs.net
- drone.abuse.ch
- dul.dnsbl.sorbs.net
- dyna.spamrats.com
- http.dnsbl.sorbs.net
- pbl.spamhaus.org
- relays.bl.kundenserver.de
- sbl.spamhaus.org
- smtp.dnsbl.sorbs.net
- socks.dnsbl.sorbs.net
- spam.abuse.ch
- spam.dnsbl.sorbs.net
- xbl.spamhaus.org
- zen.spamhaus.org
- zombie.dnsbl.sorbs.net
- '
- # pipe delimited exclude list for remote lists
- Exclude='^dnsbl.mailer.mobi$|^foo.bar$|^bar.baz$'
- # Remotely maintained list of DNSBLs to check
- WPurl="http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists"
- WPlst=$(curl -s $WPurl | egrep "<td>([a-z]+\.){1,7}[a-z]+</td>" | sed -r 's|</?td>||g;/$Exclude/d')
- # ---------------------------------------------------------------------
- HostToIP()
- {
- if ( echo "$host" | egrep -q "[a-zA-Z]" ); then
- IP=$(host "$host" | awk '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print$NF}')
- else
- IP="$host"
- fi
- }
- Repeat()
- {
- printf "%${2}s\n" | sed "s/ /${1}/g"
- }
- Reverse()
- {
- echo $1 | awk -F. '{print$4"."$3"."$2"."$1}'
- }
- Check()
- {
- result=$(dig +short $rIP.$BL)
- if [ -n "$result" ]; then
- echo -e "MAY BE LISTED \t $BL (answer = $result)"
- touch /root/mailqsend
- else
- echo -e "NOT LISTED \t $BL"
- fi
- }
- if [ -n "$1" ]; then
- hosts=$@
- fi
- if [ -z "$hosts" ]; then
- hosts=$(netstat -tn | awk '$4 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ && $4 !~ /127.0.0/ {gsub(/:[0-9]+/,"",$4);} END{print$4}')
- fi
- for host in $hosts; do
- HostToIP
- rIP=$(Reverse $IP)
- # remote list
- echo; Repeat - 100
- echo " checking $IP against BLs from $WPurl"
- Repeat - 100
- for BL in $WPlst; do
- Check
- done
- # local list
- echo; Repeat - 100
- echo " checking $IP against BLs from a local list"
- Repeat - 100
- for BL in $LocalList; do
- Check
- done
- done
chmod +x /root/blacklistcheck
add a cron job f.ex. every hour
/root/blacklistcheck