2021-01-30 07:39:48 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
ip_address="$1"
|
|
|
|
|
|
|
|
if echo "$ip_address" | grep -vqE '^([0-9]{1,3}\.){3}[0-9]{1,3}$'; then
|
|
|
|
echo "ip_address $ip_address must match "'"^([0-9]{1,3}\.){3}[0-9]{1,3}$"'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf '['
|
2021-01-30 08:03:29 +00:00
|
|
|
DELIMITER=""
|
2021-01-30 07:39:48 +00:00
|
|
|
ssh-keyscan "$ip_address" 2>/dev/null | while read -r line; do
|
|
|
|
if echo "$line" | grep -qE "^$ip_address"' +(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$'; then
|
|
|
|
KEY_CONTENT="$(echo "$line" | awk '{ print $2 " " $3 }')"
|
|
|
|
FINGERPRINT_OUTPUT="$(echo "$KEY_CONTENT" | ssh-keygen -l -E sha256 -f - | sed -E 's/^[0-9]+ SHA256:([0-9A-Za-z+/-]+) .+ \(([A-Z0-9]+)\)$/\1 \2/g')"
|
|
|
|
SHA256_HASH="$(echo "$FINGERPRINT_OUTPUT" | awk '{ print $1 }')"
|
|
|
|
KEY_TYPE="$(echo "$FINGERPRINT_OUTPUT" | awk '{ print $2 }')"
|
2021-01-30 08:03:29 +00:00
|
|
|
printf '%s\n {"key_type":"%s", "content":"%s", "sha256":"%s"}' "$DELIMITER" "$KEY_TYPE" "$KEY_CONTENT" "$SHA256_HASH"
|
|
|
|
DELIMITER=","
|
2021-01-30 07:39:48 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
printf '\n]\n'
|
2021-01-30 08:03:29 +00:00
|
|
|
|