Created
March 23, 2023 00:52
-
-
Save LuisCardenasSolis/2b73756e63935aca50a1f0e380e22b68 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# This software may be modified and distributed under the terms | |
# of the MIT license. See the LICENSE file for details. | |
DOMAINS=( | |
'www.domain.pe 443' | |
'www.domain.com 443' | |
) | |
function check_ssl_cert() | |
{ | |
host=$1 | |
port=$2 | |
proto=$3 | |
if [ -n "$proto" ] | |
then | |
starttls="-starttls $proto" | |
else | |
starttls="" | |
fi | |
cert=`openssl s_client -servername $host -host $host -port $port -showcerts $starttls -prexit </dev/null 2>/dev/null | | |
sed -n '/BEGIN CERTIFICATE/,/END CERT/p' | | |
openssl x509 -text 2>/dev/null` | |
end_date=`echo "$cert" | sed -n 's/ *Not After : *//p'` | |
end_date_seconds=`date '+%s' --date "$end_date"` | |
now_seconds=`date '+%s'` | |
end_date=$(echo "($end_date_seconds-$now_seconds)/24/3600" | bc) | |
issue_dn=`echo "$cert" | sed -n 's/ *Issuer: *//p'` | |
issuer=`echo $issue_dn | sed -n 's/.*CN=*//p'` | |
serial=`echo "$cert" | openssl x509 -serial -noout` | |
serial=`echo $serial | sed -n 's/.*serial=*//p'` | |
printf "| %32s | %5s | %-13s | %-50s |\n" "$host" "$port" "$end_date" "${issuer:0:50}" | |
} | |
printf "%s\n" "/----------------------------------------------------------------------------------------------------------------\\" | |
printf "| %32s | %5s | %-13s | %-51s |\n" "Domain" "Port" "Expire (days)" "Issuer" | |
printf "%s\n" "|----------------------------------|-------|---------------|-----------------------------------------------------|" | |
for domain in "${DOMAINS[@]}"; do | |
check_ssl_cert $domain | |
done | |
printf "%s\n" "\\-----------------------------------------------------------------------------------------------------------/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment