gpt4 book ai didi

PHP - 如何从 shell_exec 输出中获取参数

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:24 25 4
gpt4 key购买 nike

我需要获取域的 SSL 证书详细信息(如到期日期、颁发者)。为此,我从 PHP 文件运行了以下命令。

ssl.php

$cdates= shell_exec('openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates');
$issuer= shell_exec('openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -issuer');
echo "$cdates";
echo "$issuer";

获取以下输出:

notBefore=Dec 10 11:54:23 2014 GMT notAfter=Mar 10 00:00:00 2015 GMT

issuer= /C=US/O=Google Inc/CN=Google Internet Authority G2

现在我的问题是如何从变量中获取参数?

例如,我需要从 $issuer 变量中获取 CN 值(Google Internet Authority G2)。

那么是否存在任何命令/函数,或者我需要使用正则表达式从字符串中提取 CN

如有任何建议,我们将不胜感激。

最佳答案

这似乎是一种更简洁的方法(使用 phpseclib ):

<?php
include('File/X509.php');

$x509 = new File_X509();
$cert = $x509->loadX509(shell_exec('openssl s_client -connect example.com:443 2>/dev/null'));

print_r($x509->getIssuerDNProp('CN'));
?>

关于PHP - 如何从 shell_exec 输出中获取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27819897/

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