Skip to content

Instantly share code, notes, and snippets.

@0x9900
Last active August 29, 2015 14:24
Show Gist options
  • Save 0x9900/143d2add4950ebceed23 to your computer and use it in GitHub Desktop.
Save 0x9900/143d2add4950ebceed23 to your computer and use it in GitHub Desktop.
#!/bin/ksh
#
USAGE="Usage: dnsbl [-b] ipaddress"
set -A RBL_LST "zen.spamhaus.org" "bl.spamcop.net" \
"b.barracudacentral.org" "cbl.abuseat.org" \
"hostkarma.junkemailfilter.com"
if [[ $# < 1 || $# > 2 ]]; then
echo $USAGE
exit 1
fi
if [[ $1 == "-b" ]]; then
BLOCK=1
shift
fi
if [[ $# != 1 ]]; then
echo $USAGE
exit 1
fi
ip=${1}
revip=$(IFS=.; set -- $ip ; echo "${4}.${3}.${2}.${1}")
for rbl_server in ${RBL_LST[@]}; do
result=$(dig +short "${revip}.${rbl_server}")
if echo ${result} | grep -q "127\.0\.0\.2"; then
[[ $BLOCK == 1 ]] && {
sudo spamdb -t -a $ip
echo -n "blocking "
}
echo -n "${ip} found on ${rbl_server}\n"
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment