Skip to content

Instantly share code, notes, and snippets.

@bkenny
Created July 12, 2011 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkenny/1077680 to your computer and use it in GitHub Desktop.
Save bkenny/1077680 to your computer and use it in GitHub Desktop.
SSH Key Port Scanning
#/bin/sh
# Script to check if port 22 (SSH) is open within the range, secondly if our SSH key is accepted by that server.
# Insert your SSH Key here
KEYPUB="/link/root/.ssh/file";
RANGES="0.0.0.0/0 1.1.1.1/1"
for i in `nmap -sT -n -p 22 -P0 -oG - $RANGES | grep open | awk '{print $2}'`
do
ssh -i $KEYPUB -q -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@$i exit 2>&1 >/dev/null
if [ "$?" = "0" ]; then
# echo the IP of the server into the document.
echo $i >> log-file-of-servers-allowing-connection.txt
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment