rblog

Firewall verification using a script

Needed to verify a lot of ports that should be opened making it possible to connect to three hosts. Had to do some surfing, and as always by the help of Google I managed to create a bash-script solving the issue for me.


#!/bin/bash
 
###### Set variables ########
# IP of WAS-server 4,5,6
PREIP=10.10.31.
POSTIP="4;5;6"
# Use Notepad++ and see http://ccapeng.blogspot.no/2008/06/notepad-replace-pattern-with-line-break.html to create the below listings
CSIV2_SSL="10113;10036;10046;10056;10066;10076;10086;10096"
ORB_LISTENER="10014;10024;10034;10044;10054;10064;10074"
BOOTSTRAP="10111;10032;10042;10052;10062;10072;10082"
 
###### DO THE MAGIC ######
echo "Testing from `hostname`"
echo "***********************"
# Use of IFS, see http://stackoverflow.com/questions/918886/split-string-based-on-delimiter-in-bash
OIFS=$IFS
IFS=';' read -ra IPARR <<< "$POSTIP"
for ip  in "${IPARR[@]}";
do
    MACHINE=$PREIP$ip
    echo ""
    echo "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤"
    echo "Testing connectivity against ip $MACHINE"
    echo "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤"
    echo ""
    echo "Checking CSIV2_SSL_SERVERAUTH_LISTENER_ADDRESS"
    IFS=';' read -ra CSIV2ARR <<< "$CSIV2_SSL"
    for port in "${CSIV2ARR[@]}";
    do
        # Ignore errors, instead print below
        exec 3>/dev/tcp/${MACHINE}/$port 2>/dev/null
        if [ $? -eq 1 ]
        then
            #Only report errors, ret.value = 1 (success = 0)
                echo "Telnet connections not possible on port $port"
        fi
    done
    
    #...as above, for the rest of the ports needed to be checked, 
    #...copy the above statements and change the source variable.
    #...a bit dirty, but hey, solving a one time issue...who cares :-)

done
# Set IFS back to old value
IFS=$OIFS