Browse Source

SSL证书期限查询

Moeyuuko 1 year ago
parent
commit
3ed95ed042
1 changed files with 16 additions and 0 deletions
  1. 16 0
      SSL_Certificate_Period.sh

+ 16 - 0
SSL_Certificate_Period.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+host=$1
+port=${2:-"443"}
+
+end_date=`timeout 6 openssl s_client -host $host -port $port -showcerts </dev/null 2>/dev/null |
+sed -n '/BEGIN CERTIFICATE/,/END CERT/p' |
+openssl x509 -text 2>/dev/null |
+sed -n 's/^[[:space:]]\+Not After ://p'`
+#echo "$end_date"
+
+if [ -n "$end_date" ];then
+end_date_seconds=`date '+%s' --date "$end_date"`
+now_seconds=`date '+%s'`
+echo "($end_date_seconds - $now_seconds)/24/3600"|bc
+fi