Created
October 14, 2020 14:47
-
-
Save marc-hanheide/0777c0d97d7795949d7edf14a8d5844c to your computer and use it in GitHub Desktop.
Find all ssh host keys on a network segment
This file contains 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 characters
#!/bin/bash | |
SUBNET="10.5.42.0/24 | |
# compare the output to your ~/.ssh/known_hosts list | |
for ip in `nmap -p 22 --open -oG - $SUBNET | grep '22/open' | cut -f2 -d" " `; do key="`ssh-keyscan -H -t rsa $ip 2>&1| grep -v '^# '`"; if [ "$key" ]; then echo "$ip $key"; fi ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment