So you want to regularly check your IP(s) if they got listed on one of the many (800+ to be exact)  public blacklists (also known as DNSBL or RBL)?

Bellow, you can find a bash script that will make your life much easier. You can also make a cronjob that sends you an email with the results or simply display the results with PHP.

# 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
# Last updated on 20.02.2019 @


# 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

  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  "IMHO '$1' doesn't look like a valid IP address"
      exit 1

# Assuming an IP address of as parameter or argument

# If the IP address in $0 passes our crude regular expression check,
# the variable  ${reverse} will contain
# In this case the test will be:
#   [ "x44.33.22.11" = "x" ]
# This test will fail and the program will continue

# An empty '${reverse}' means that shell argument $1 doesn't pass our simple IP address check
# In that case the test will be:
#   [ "x" = "x" ]
# This evaluates to true, so the script will call the ERROR function and quit

# -- 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:----}

Have questions regarding e-mail blacklists and how they work? Well, when I have more time I will surely post about it but for now, you may just leave a comment below and I will reply when I can.


  1. Ghislain

    HI Denis,
    You could make the reversed IP with something like that, which is more readable):
    reverse=$($1 | awk -F “.” ‘{print $4″.”$3″.” $2″.”$1}’)

  2. StraGeKa

    Can you make an update of the script?
    a) example add more domain, IP4 and IP6 black list checks
    b) if it is blacklisted also add after result the word “Blacklisted”
    c) we can run the script one time for multiple domains, ip4 and ip6
    and filter out only Blacklisted

    # Pipe with other UNIX utils, eg. grep. Only blacklisted:
    $ ./bl domain.tld | grep “blacklisted”

    example is here

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.