Spamhaus listing check

Spamhaus kindly keep a list of threatening domains and IP addresses that the update frequently. Great idea but it's also susceptible to false inclusion. Whilst they have a process to assist in removal of false entries it all takes time. As a side effect gmail/google keep track of this list and then make their own 'we don't like you list'.

Now if you run your own smtp server, and your ISP uses IP ranges are considered 'home use' then periodically, say every 12 months, it seems that you get a new automatic entry on the spamhaus naughty IP list.

See where I'm heading here? Yep, I change ISP's about 12 months ago and found my public IP on the list, asked for it to be removed and all was well. Promptly forgot about it and here we are 12 months later. Pinged again, gmail/google added my IP onto their 'we don't want little people to have their own smtp server so we'll block you list. Now that's a whole new round of entertainment because the google god's don't care. The the extent that your only recourse is to suck it up for an indeterminate period of time and pray it'll be resolved or for you to use an external smtp relay service.

Any way, having reconfigured my smtp server to now use an external relay service, I'd still like to know if I attract the attention of spamhaus as other systems use their listing and I'd prefer to be only banned by places that I purposely want to be banned by.

Using the power of google (payback's a bitch) I searched for automatic spamhaus listing checks and found the following code (linux based only).

Run this check daily on mail server to check for issues with spamhaus listing
in /etc/cron.d/check-spamhaus

# daily spamhaus check
4/10/26 0 8 * * * /usr/local/bin/check-spamhaus.sh


in /usr/local/bin/check-spamhaus.sh

#!/bin/bash TARGET_IP="192.0.2.1" # Change to your IP
REVERSED_IP=$(echo "$TARGET_IP" | awk -F. '{print $4"."$3"."$2"."$1}') QUERY="${REVERSED_IP}.zen.spamhaus.org"
RESULT=$(dig +short "$QUERY")
if [ -n "$RESULT" ]; then
    echo "ALERT: IP $TARGET_IP is listed on Spamhaus (Code: $RESULT)" | mail -s
"Spamhaus Listing Alert: $TARGET_IP" admin@yourdomain
else
    echo "IP $TARGET_IP is clean."
fi

sends email warning if listed

The target IP 192.0.2.1 is listed so you can test for IP inclusion prior to editing your actual IP.

Now we have an automatic daily (or whatever schedule you decide on) check for you public IP being listed on spamhaus.