Script to check – Mail server IP addr is blacklisted or not?
Introduction –
This shell script can be used to known whether the IP address of your mail server is black list or not…
Who can use this script ?
– System Admin, Mail Server admin or any one who want to find the IP address is black listed or not?
root@arunbagul:/home/arun/bash-prog# cat black_white_listing.sh
#!/bin/bash
echo “=========================================”
echo “Welcome to IndianGNU.org’s script to check the Blacklisting”
if [ $# -eq 0 ]; then
echo -n “Enter the IP Address of Mail Server: ”
#read the IP from cmd line
read IPAddr
else
IPAddr=$1
fi
#Reverse the IP…
ipaddr1=$(echo $IPAddr | awk -F. ‘{print $1}’)
ipaddr2=$(echo $IPAddr | awk -F. ‘{print $2}’)
ipaddr3=$(echo $IPAddr | awk -F. ‘{print $3}’)
ipaddr4=$(echo $IPAddr | awk -F. ‘{print $4}’)
##check the IP format here…
if [ “$ipaddr1” == “” ]; then
echo “Please enter the Valid IP address”
exit
elif [ “$ipaddr2” == “” ]; then
echo “Please enter the Valid IP address”
exit
elif [ “$ipaddr3” == “” ]; then
echo “Please enter the Valid IP address”
exit
elif [ “$ipaddr4” == “” ]; then
echo “Please enter the Valid IP address”
exit
fi
### create reverse IP
RevIP=”${ipaddr4}.${ipaddr3}.${ipaddr2}.${ipaddr1}”
echo “The IP (Reverse format):- ${RevIP}”
###################################
for check in {blocked.hilli.dk blacklist.sci.kun.nl,spamsources.dnsbl.info,map.spam-rbl.com \
mail-abuse.blacklist.jippg.org catchspam.com spam.blackhole.cantv.net blackholes.uceb.org dnsbl.solid.net}
do
#run cmd to check the IP black listed or not
dig ${RevIP}.$check >> /dev/null
if [ $? = 0 ]; then
echo “The ${IPAddr} IS White Listed”
else
echo “The ${IPAddr} IS Black Listed”
fi
done
#done
root@arunbagul:/home/arun/bash-prog#
How to use this script ?
root@arunbagul:/home/arun/bash-prog# ./black_white_listing.sh
=========================================
Welcome to IndianGNU.org’s script to check the Blacklisting
Enter the IP Address: 192.168.0.1
The IP (Reverse format):- 1.0.168.192
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
The 192.168.0.1 IS White Listed
root@arunbagul:/home/arun/bash-prog#
Thank you,
Arun Bagul