Skip to content

Instantly share code, notes, and snippets.

@lilithmooncohen
Last active August 29, 2015 14:05
Show Gist options
  • Save lilithmooncohen/42e4d8b4a9abbffb28c0 to your computer and use it in GitHub Desktop.
Save lilithmooncohen/42e4d8b4a9abbffb28c0 to your computer and use it in GitHub Desktop.
#!/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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment