Skip to content

Instantly share code, notes, and snippets.

@kevinkjt2000
Created May 29, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinkjt2000/f6de9eadaf11bad93b7d3ecfbabc4099 to your computer and use it in GitHub Desktop.
Save kevinkjt2000/f6de9eadaf11bad93b7d3ecfbabc4099 to your computer and use it in GitHub Desktop.
#!/bin/bash
#find all of the hosts listed in ~/.ssh/config
#apparently finding all the hosts ip/dns values is not trivial
grep -oPz 'Host .*\n HostName .*' ~/.ssh/config |
sed -n 'N;s/Host \(.*\)\n HostName \(.*\)/\1\n\2/p' |
while read hosts && read hostname; do
echo "$hostname"
if [[ "$hostname" == "%h"* ]]; then
for host in $hosts; do
echo " ${hostname//'%h'/$host}"
done
else
echo " $hostname"
fi |
while read host; do
echo -n " "
ssh-keygen -lf <(ssh-keyscan $host 2>/dev/null | awk '{print $2 " " $3 " " $1}')
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment