Created
May 23, 2011 16:02
-
-
Save brenttheisen/986947 to your computer and use it in GitHub Desktop.
Bash script that I run in cron that emails me every time my Slicehost VMs get added back in to the Spamhaus PBL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() | |
{ | |
cat << EOF | |
usage: $0 <ip> [blocklist] | |
ip The IP to check. | |
blocklist The Spamhaus block list to check. Defaults to zen but can be one of these: zen, sbl, xbl, pbl or dbl. | |
EOF | |
} | |
if [ -z "$1" ]; then | |
usage | |
exit | |
fi | |
IP_ADDR=$1 | |
if [ -z "$2" ]; then | |
BLOCK_LIST=zen | |
else | |
BLOCK_LIST="$2" | |
fi | |
IFS='.'; read -ra ADDR <<< "$IP_ADDR" | |
REVERSE_ADDR="" | |
for i in "${ADDR[@]}"; do | |
if [ -z "$REVERSE_ADDR" ]; then | |
REVERSE_ADDR="${i}" | |
else | |
REVERSE_ADDR="${i}.${REVERSE_ADDR}" | |
fi | |
done | |
OUTPUT=`host "${REVERSE_ADDR}.${BLOCK_LIST}.spamhaus.org"` | |
if [[ "$OUTPUT" =~ "has address" ]]; then | |
echo "${IP_ADDR} is in the ${BLOCK_LIST} Spamhaus block list" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment