Created
December 6, 2019 00:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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