首页 > 其他分享 >https证书过期时间查询脚本

https证书过期时间查询脚本

时间:2022-09-30 14:24:04浏览次数:55  
标签:Domain log 证书 过期 echo awk https print Port

#!/bin/bash
file=$1
expire=$2
function start() {
    rm -rf ./info.log ./list.txt ./res.txt ./end.txt ./res_${file}
}
function get_domain() {
    cat $file | egrep -v "^_" | awk '{print $1}' | sed 's/net./net/g' > list.txt
}
function get_expire() {
    log=./info.log
    for Domain in `cat list.txt`
    do
        Port_List=`nmap -Pn -T 5 $Domain |grep -w "open" |awk -F'/' '{print $1}'`
        echo "--- $Domain ---" | tee >> $log
        echo "open port: `echo $Port_List`" | tee >> $log 
        for Port in $Port_List
        do
            Info=`openssl s_client -servername $Domain -connect $Domain:$Port < /dev/null | openssl x509 -noout -dates -subject`
            #If SSL is not turned on, the loop exits
            if [ -z "$Info" ]
            then
                echo "Port $Port SSL is not enabled" | tee >> $log
                continue
            else
                echo "Port $Port SSL is enabled" | tee >> $log
            fi
            StartTime=`echo $Info| awk -F'=' '{print $2}'|awk '{$NF="";print $0}'|xargs -I {} date '+%Y-%m-%d' --date {}` 
            EndTime=`echo $Info | awk -F'=' '{print $3}'|awk '{$NF="";print $0}'| xargs -I {} date '+%Y-%m-%d' --date {}` 
            Domain_Name=`echo $Info | awk -F'=' '{print $5}'`
            echo "  $Domain:$Port SSL domain: $Domain_Name" | tee >> $log
            echo "  $Domain:$Port SSL StartTime: $StartTime" | tee >> $log  
            echo "  $Domain:$Port SSL EndTime: $EndTime" | tee >> $log  
        done
    done
    cat ./info.log | grep "EndTime: $expire" > res.txt
}

function get_ip() {
    for domain in `cat res.txt | awk '{print $1}' | awk -F: '{print $1}'`
    do
        while read line 
        do 
            echo $line | grep $domain
            if [ $? -eq 0 ];then
                echo $line | awk '{print $5}' >> res_${file}
            fi
        done < $file
    done             
}

function get_result() {
    sort -k2n res_${file} | awk '{if ($0!=line) print;line=$0}' > ip_${file}
}

start
get_domain
get_expire
get_ip
get_result

 

标签:Domain,log,证书,过期,echo,awk,https,print,Port
From: https://www.cnblogs.com/fengzi7314/p/16744750.html

相关文章