gpt4 book ai didi

linux - 获取 -enddate 时 Openssl 输出挂起

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:08:09 24 4
gpt4 key购买 nike

我一直在编写一个脚本来获取一些证书的详细信息,而不是我已经在解决格式问题的过程中得到了格式化,现在当我尝试解析 EndDate="openssl s_client 时,脚本挂起-connect $host:$port 2>/dev/null | openssl x509 -enddate -noout | grep "Not After"| awk '{print $4, $5, $7}'”

这是我目前正在编写的完整脚本以供引用,其中大部分内容都是一起破解的,因为我刚刚掌握了脚本编写的窍门。

# User input for the host or url of the certificate to check 
echo "What host IP or URL certificate would you like to check: "
read host
# User input for the port number of the certificate to check
echo "What is the port number for the host's IP or URL: "
read port
# Input Verification post
echo "Host connection information = $host:$port"
# openssl expiration date checks for the week
echo "::Certificate expiration date::"
EndDate=`openssl s_client -connect $host:$port 2>/dev/null | openssl x509 - enddate -noout | grep "Not After" | awk '{print $4, $5, $7}'`
DatePlus7=`date -ud "+7 day" | awk '{print $2, $3, $6}'`
if [ "$EndDate" = "$DatePlus7"]
then
echo "Certificate has expired or will do so within 7 days!"
echo "(or is invalid/not found)"
else
echo "Certificate is good for another week!"
fi

最终我希望能够输出echo | openssl s_client-connect $host:$port 2>/dev/null | openssl x509 -enddate -noout 以及管理员,这出现在 fi 语句之后。谁能帮我解决这个问题?

最佳答案

从小处着手进行构建比从大处着手并向下调试更容易。

这里有一个更简单的方法来重现您的问题,它也只是挂起:

openssl s_client -connect google.com:443

既然问题是如此简单和狭隘,谷歌搜索“为什么 openssl s_client 会挂起?”导致 useful information推荐 echo -n | ... 以“给服务器一个响应,以便释放连接”。这应该足以让我们走得更远(还有其他问题)。

无论如何,这里有一个更短的方法:

if openssl s_client -connect google.com:443 2> /dev/null < /dev/null |
openssl x509 -checkend $((60*60*24*7)) -noout -in /dev/stdin
then
echo "The certificate is good."
else
echo "The certificate expires within a week."
fi

关于linux - 获取 -enddate 时 Openssl 输出挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34007890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com