【发布时间】:2017-11-06 19:07:53
【问题描述】:
假设您在一个文本文件中有一千个 IP 地址的列表 - 每行一个。我希望能够使用 openssl s_client 命令从每个 IP 地址中获取所有可能的异常。到目前为止,异常是证书过期、自签名证书和颁发者 CN 包括 emailAddress=root@localhost.localdomain。
总的来说,如果有的话,我希望能够获得每个 IP 地址的简明错误消息。我当前的 bash 脚本如下所示:
for ip in `awk '{print $1}' < general_certs.txt`; do
# Print IP address currently checking
echo -e $ip;
if timeout 30 openssl s_client -connect $ip:443| grep -i 'error' ; then
# Write error information and IP address to a file
echo `openssl s_client -connect $ip:443| grep -i 'error'` $ip >> general_errors;
else
# Write noerror information and IP address to another file
echo "noerror" $ip >> general_noerror;
fi;
done
我对代码的第一个问题是它没有优化,我怀疑它是否返回准确的结果。上述脚本的最终目标是识别所有包含 IP 的不受信任的证书。
我在上面的代码中遇到的第二个问题是我无法先回显 $ip,因为它会被消息本身截断。所以,我最终在错误消息之后写出了 $ip 。
如果我的问题有更真实的解决方案,就不用用openssl了。
【问题讨论】: