Skip to content

Instantly share code, notes, and snippets.

@porjo
Created December 6, 2019 00:29
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 porjo/5df4f26331ab6ae6939c08aa6ab4a03a to your computer and use it in GitHub Desktop.
Save porjo/5df4f26331ab6ae6939c08aa6ab4a03a to your computer and use it in GitHub Desktop.
Given a list of IP addresses (in file 'ips') find what the SSL CN (subject) is for each one.
#!/bin/bash
# Given a list of IP addresses (in file 'ips') find what the SSL CN (subject) is for each one.
echo -en "IP\tSSL CN\n"
for i in `cat ips`; do
echo -en "$i\t"
out=`timeout 2 bash -c "openssl s_client -showcerts -connect $i:443 < /dev/null 2> /dev/null | openssl x509 -noout -subject 2> /dev/null | grep 'subject=' | sed -rn 's/.*CN=([^ /]+).*/\1/p'"`
if [ $? -eq 124 ]; then
echo "(timeout)"
elif [ -z $out ]; then
echo "(unknown)"
else
echo $out
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment