Skip to content

Instantly share code, notes, and snippets.

@marc-hanheide
Created October 14, 2020 14:47
Show Gist options
  • Save marc-hanheide/0777c0d97d7795949d7edf14a8d5844c to your computer and use it in GitHub Desktop.
Save marc-hanheide/0777c0d97d7795949d7edf14a8d5844c to your computer and use it in GitHub Desktop.
Find all ssh host keys on a network segment
#!/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