Last active
June 24, 2020 19:20
-
-
Save skinsch/ba0bfd310b414baf85c93b3d7e5292ef to your computer and use it in GitHub Desktop.
Check IP against Mail Blacklists
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 | |
# -- head.tmpl v0.06 -------------------------------------------------------- | |
BASE=~/projects/mail | |
export PATH=${PATH}:/usr/bin:/usr/local/sbin:/sbin:/usr/local/bin:${BASE} | |
[ "`basename -- "$0"|cut -f1 -d.`" = "mk" ] && script=$(basename -- "$0"|cut -f1-2 -d.) || script=$(basename -- "$0"|cut -f1 -d.) | |
bs=${BASE}/${script} | |
csv=${bs}.csv; raw=${bs}.raw; log=${bs}.log; tmp=${bs}.tmp; | |
in=${bs}.in; out=${bs}.out; exm=${bs}.exempt | |
. ~/colors.inc 2>/dev/null | |
# Check if an IP address is listed on one of the following blacklists | |
# The format is chosen to make it easy to add or delete | |
# The shell will strip multiple whitespace | |
. dnsbl.inc | |
# simple shell function to show an error message and exit | |
# $0 : the name of shell script, $1 is the string passed as argument | |
# >&2 : redirect/send the message to stderr | |
ERROR() { | |
echo $0 ERROR: $1 >&2 | |
exit 2 | |
} | |
# -- Sanity check on parameters | |
[ $# -ne 1 ] && ERROR 'Please specify a single IP address' | |
# -- if the address consists of 4 groups of minimal 1, maximal digits, separated by '.' | |
# -- reverse the order | |
# -- if the address does not match these criteria the variable 'reverse will be empty' | |
reverse=$(echo $1|sed -ne "s~^\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)$~\4.\3.\2.\1~p") | |
if [ "x${reverse}" = "x" ] ; then | |
ERROR "$0: '$1' doesn't look like a valid IP address" | |
exit 1 | |
fi | |
# -- do a reverse ( address -> name) DNS lookup | |
REVERSE_DNS=$(dig +short -x $1) | |
echo IP $1 NAME ${REVERSE_DNS:----} | |
# -- cycle through all the blacklists | |
for BL in ${BLISTS} ; do | |
# show the reversed IP and append the name of the blacklist | |
printf "%-60s" " ${reverse}.${BL}." | |
# use dig to lookup the name in the blacklist | |
#echo "$(dig +short -t a ${reverse}.${BL}. | tr '\n' ' ')" | |
LISTED="$(dig +short -t a ${reverse}.${BL}.)" | |
echo ${LISTED:----} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment