Skip to content

Instantly share code, notes, and snippets.

@hotpxl
Created September 8, 2016 07:12
Show Gist options
  • Save hotpxl/2fab01912695467d74e04d3bf80bd8fa to your computer and use it in GitHub Desktop.
Save hotpxl/2fab01912695467d74e04d3bf80bd8fa to your computer and use it in GitHub Desktop.
Get SSHFP record
#!/bin/bash
set -euo pipefail
print_usage() {
printf "Usage: %s <fully qualified domain names>...\n" "$(basename "$0")"
exit 1
}
if [[ "$#" -lt 1 ]]; then
print_usage
fi
signatures=$(ssh-keyscan "$@" 2> /dev/null)
if [[ "${signatures}" == "" ]]; then
exit 1
fi
array=()
while IFS= read -r line; do
domain=$(echo "${line}" | cut -d " " -f 1)
signature=$(echo "${line}" | cut -d " " -f "2-")
dns_rr=$(ssh-keygen -r "${domain}" -f <(echo "${signature}"))
while IFS= read -r rr; do
array+=("${rr}")
done <<< "${dns_rr}"
done <<< "${signatures}"
IFS=$'\n'
echo "${array[*]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment