Last active
August 29, 2015 14:05
Revisions
-
Ryan C Koch revised this gist
Aug 19, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -60,7 +60,7 @@ if [ ! -f $KEYFILE ] ; then fi # PROMPT FOR PORT NUMBER read -p 'PORT TO CHECK [80]: ' -r if [ -n "$REPLY" ] ; then if [[ $REPLY =~ ^-?[0-9]+$ ]] ; then PORT=$REPLY @@ -69,7 +69,7 @@ if [ -n "$REPLY" ] ; then exit 1 fi else PORT="80" fi # PROMPT FOR PROTOCOL -
Ryan C Koch revised this gist
Aug 19, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # ------------------------------------------------------------------ # Author: Ryan C Koch - ryanckoch@gmail.com # Purpose: CHECK TCP AND UDP CONNECTIVITY BETWEEN # SOURCE AND DESTINATION HOSTS # ------------------------------------------------------------------ -
Ryan C Koch revised this gist
Aug 19, 2014 . 1 changed file with 164 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,71 +1,201 @@ #!/bin/bash # ------------------------------------------------------------------ # Author: Ryan C Koch - [email protected] # Purpose: CHECK TCP AND UDP CONNECTIVITY BETWEEN # SOURCE AND DESTINATION HOSTS # ------------------------------------------------------------------ SOURCE_FILE="source.hosts" DESTINATION_FILE="destination.hosts" LOG_VERBOSE="logs/verbose.log" LOG_SSH_ERROR="logs/ssh_error.log" LOG_COMPLETED="logs/completed.log" LOG_ERRORED="logs/errored.log" #VERIFY SOURCE AND DESTINATION FILES EXIST if [ ! -f $SOURCE_FILE ] || [ ! -f $DESTINATION_FILE ]; then echo 'SOURCE AND/OR DESTINATION FILE DO NOT EXIST. EXITING.' exit 1 fi # PARSE SOURCE AND DESTINATIONS FILES INTO ARRAYS declare -a SOURCES_ARRAY declare -a DESTINATIONS_ARRAY readarray -t SOURCES_ARRAY < $SOURCE_FILE readarray -t DESTINATIONS_ARRAY < $DESTINATION_FILE # VERIFY SOURCE AND DESTINATIONS WERE NOT EMPTY if [ ${#SOURCES_ARRAY[@]} -eq 0 ] || [ ${#DESTINATIONS_ARRAY[@]} -eq 0 ] ; then echo 'SOURCE OR DESTINATION FILE IS EMPTY. EXITING NOW.' | tee -a $LOG_VERBOSE exit 1 fi #VERIFY LOG DIRECTORY EXISTS AND IF NOT, CREATE IT if [ ! -d logs ] ; then mkdir logs fi # PROMPT FOR USERNAME USERNAME=`whoami` read -p 'SSH USERNAME ['$USERNAME']: ' -r if [ -n "$REPLY" ] ; then USERNAME=$REPLY fi # PROMPT FOR SSH KEY read -p 'USE SSH KEY ~/.ssh/id_rsa ([y]/n)?: ' -r if [[ $REPLY =~ ^[Yy]$ ]] || [ -z "$REPLY" ] ; then KEYFILE=~/.ssh/id_rsa elif [[ $REPLY =~ ^[nN]$ ]] ; then read -p 'SSH KEY (FULL PATH): ' -r KEYFILE=$REPLY else echo 'INVALID INPUT. EXITING. NOTHING EXECUTED.' exit 1 fi if [ ! -f $KEYFILE ] ; then echo 'SSH KEY NOT FOUND. EXITING. NOTHING EXECUTED.' exit 1 fi # PROMPT FOR PORT NUMBER read -p 'PORT TO CHECK [3306]: ' -r if [ -n "$REPLY" ] ; then if [[ $REPLY =~ ^-?[0-9]+$ ]] ; then PORT=$REPLY else echo 'INVALID INPUT. EXITING. NOTHING EXECUTED.' exit 1 fi else PORT="3306" fi # PROMPT FOR PROTOCOL read -p 'UDP or TCP? [tcp]: ' -r if [ -n "$REPLY" ] ; then if [ ${REPLY,,} == "tcp" ] || [ ${REPLY,,} == "udp" ] ; then PROTO=${REPLY,,} else echo 'INVALID INPUT. EXITING. NOTHING EXECUTED.' exit 1 fi else PROTO="tcp" fi echo # OUTPUT INFO echo '*******************' echo 'SSH USER: '$USERNAME echo '*******************' echo 'SSH KEY: '$KEYFILE echo '*******************' echo 'PORT TO CHECK: '$PORT echo '*******************' echo 'PROTOCOL: '$PROTO echo '*******************' echo 'SOURCE HOSTS: ' for SOURCE_HOST in "${SOURCES_ARRAY[@]}" ; do echo $SOURCE_HOST done echo '*******************' echo 'DESTINATION HOSTS: ' for DESTINATION_HOST in "${DESTINATIONS_ARRAY[@]}" ; do echo $DESTINATION_HOST done echo '*******************' echo # VERIFY WITH USER ABOVE INFO IS CORRECT read -p 'IS THIS CORRECT ([y]/n)?: ' -r echo if [[ $REPLY =~ ^[Yy]$ ]] || [ -z "$REPLY" ] ; then echo '' elif [[ $REPLY =~ ^[nN]$ ]] ; then echo 'EXITING BASED ON USER INPUT. NOTHING EXECUTED.' exit 0 else echo 'INVALID INPUT. EXITING. NOTHING EXECUTED.' exit 1 fi echo echo 'VERIFYING SSH ACCESS ON SOURCE HOSTS' echo TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"` echo '*******************SSH CHECK BEGIN '$TIMESTAMP'*******************' | tee -a $LOG_VERBOSE $LOG_SSH_ERROR # VERIFY SSH ACCESS TO SOURCE HOSTS declare -a SSH_SUCCESS_ARRAY declare -a SSH_FAILED_ARRAY for SOURCE_HOST in "${SOURCES_ARRAY[@]}" ; do echo $SOURCE_HOST | tee -a $LOG_VERBOSE ssh -i $KEYFILE -n -o BatchMode=yes -o StrictHostKeyChecking=no $USERNAME@$SOURCE_HOST 'echo "SSH CONNECTION SUCCESFUL"' >> $LOG_VERBOSE 2>&1 if [ 0 = $? ]; then SSH_SUCCESS_ARRAY+=($SOURCE_HOST) echo 'SSH CONNECTION SUCCESFUL' else SSH_FAILED_ARRAY+=($SOURCE_HOST) echo 'SSH CONNECTION FAILED' | tee -a $LOG_VERBOSE echo $SOURCE_HOST >> $LOG_SSH_ERROR fi done echo | tee -a $LOG_VERBOSE if [ ${#SSH_FAILED_ARRAY[@]} -eq 0 ]; then echo | tee -a $LOG_VERBOSE echo "SSH ACCESS TO ALL SOURCE HOSTS SUCCESFUL" | tee -a $LOG_VERBOSE elif [ ${#SSH_FAILED_ARRAY[@]} -eq 0 ]; then echo | tee -a $LOG_VERBOSE echo "SSH FAILED ON ALL SOURCE HOSTS" | tee -a $LOG_VERBOSE echo "EXITING NOW" | tee -a $LOG_VERBOSE exit 1 else echo "SSH FAILED ON THE FOLLOWING SOURCE HOSTS: " | tee -a $LOG_VERBOSE for SSH_FAILED_HOST in "${SOURCES_ARRAY[@]}" ; do echo $SSH_FAILED_HOST | tee -a $LOG_VERBOSE done echo | tee -a $LOG_VERBOSE echo "UNSUCCESFUL HOSTS ARE LISTED IN LOG FILE" | tee -a $LOG_VERBOSE echo "CONTINUING ON TO NEXT STEP FOR SUCCESFUL HOSTS" | tee -a $LOG_VERBOSE fi echo | tee -a $LOG_VERBOSE TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"` echo '*******************SSH CHECK END'$TIMESTAMP'*******************' | tee -a $LOG_VERBOSE $LOG_SSH_ERROR echo | tee -a $LOG_VERBOSE $LOG_SSH_ERROR echo echo 'INITIATING PORT CHECKS' echo echo | tee -a $LOG_VERBOSE $LOG_COMPLETED $LOG_ERRORED TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"` echo '*******************PORT CHECK BEGIN '$TIMESTAMP'*******************' | tee -a $LOG_VERBOSE $LOG_COMPLETED $LOG_ERRORED # RUN PORT CHECKS ON SOURCE HOSTS for SSH_SUCCESS_HOST in "${SSH_SUCCESS_ARRAY[@]}" ; do for DESTINATION_HOST in "${DESTINATIONS_ARRAY[@]}" ; do echo $SSH_SUCCESS_HOST' > '$PORT' > '$PROTO' > '$DESTINATION_HOST | tee -a $LOG_VERBOSE ssh -i $KEYFILE -n -o BatchMode=yes -o StrictHostKeyChecking=no $USERNAME@$SSH_SUCCESS_HOST "cat < /dev/$PROTO/$DESTINATION_HOST/$PORT" >> $LOG_VERBOSE 2>&1 if [ 0 = $? ]; then echo 'CONNECTION ESTABLISHED' | tee -a $LOG_VERBOSE echo $SSH_SUCCESS_HOST' > '$PORT' > '$PROTO' > '$DESTINATION_HOST >> $LOG_COMPLETED else echo 'CHECK FAILED' | tee -a $LOG_VERBOSE echo $SSH_SUCCESS_HOST' > '$PORT' > '$PROTO' > '$DESTINATION_HOST >> $LOG_ERRORED fi echo echo >> $LOG_VERBOSE done done TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"` echo '*******************PORT CHECK END '$TIMESTAMP'*******************' | tee -a $LOG_VERBOSE $LOG_COMPLETED $LOG_ERRORED echo | tee -a $LOG_VERBOSE $LOG_COMPLETED $LOG_ERRORED echo echo 'PORT CHECKS COMPLETE' -
Ryan C Koch revised this gist
Aug 19, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ echo '*******************' echo 'SOURCE HOSTS: ' cat source.txt echo '*******************' echo 'DESTINATION HOSTS: ' cat destination.txt echo '*******************' echo -
Ryan C Koch revised this gist
Aug 19, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,6 @@ cat destination.txt echo '*******************' echo read -p 'IS THIS CORRECT (y/n)? ' -r echo if [[ $REPLY =~ ^[Yy]$ ]] @@ -48,7 +47,6 @@ echo 'INITIATING PORT CHECKS' echo for SOURCE_HOST in `cat source.txt` ; do for DESTINATION_HOST in `cat destination.txt` ; do echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST >> verbose.log -
Ryan C Koch created this gist
Aug 19, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ #!/bin/bash if [ ! -f source.txt ] && [ ! -f destination.txt ]; then echo 'SOURCE & DESTINATION FILES DO NOT EXIST. EXITING.' exit 0 fi echo read -p 'SSH USERNAME: ' -r USERNAME=$REPLY read -p 'PORT TO CHECK: ' -r PORT=$REPLY echo echo echo '*******************' echo 'SSH USER '$USERNAME echo '*******************' echo 'PORT: '$PORT echo '*******************' echo 'SOURCE HOSTS: ' cat source.txt echo '*******************' echo 'DESTINATION HOSTS' cat destination.txt echo '*******************' echo ##VERIFY AGAIN read -p 'IS THIS CORRECT (y/n)? ' -r echo if [[ $REPLY =~ ^[Yy]$ ]] then echo '' elif [[ $REPLY =~ ^[nN]$ ]] then echo 'EXITING BASED ON USER INPUT. NOTHING EXECUTED.' exit 0 else echo 'INVALID INPUT. EXITING. NOTHING EXECUTED.' exit 0 fi echo echo 'INITIATING PORT CHECKS' echo for SOURCE_HOST in `cat source.txt` ; do #echo 'SOURCE: '$SOURCE_HOST for DESTINATION_HOST in `cat destination.txt` ; do echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST >> verbose.log ssh -o StrictHostKeyChecking=no $USERNAME@$SOURCE_HOST "cat < /dev/tcp/$DESTINATION_HOST/$PORT" if [ 0 = $? ]; then { echo 'CONNECTION ESTABLISHED' echo 'CONNECTION ESTABLISHED' >> verbose.log echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST >> complete.log } else { echo 'CONNECTION FAILED' echo 'CONNECTION FAILED' >> verbose.log echo $SOURCE_HOST' > '$PORT' > '$DESTINATION_HOST >> errors.log } fi done done echo echo 'PORT CHECKS COMPLETE' exit 0