通过PHP获取域名到期日期

发布于 2024-11-18 22:03:28 字数 713 浏览 3 评论 0原文

这是我当前的代码:

function get_cmd ()
{
    if (file_exists('/usr/local/bin/whois'))
        $cmd = '/usr/local/bin/whois';
    elseif (file_exists('/usr/bin/whois'))
        $cmd = '/usr/bin/whois';
    elseif (file_exists('/bin/whois'))
        $cmd = '/bin/whois';
    else
        die('whois shell command does not exist');

    return $cmd;
}

function get_whois ($cmd, $domain) 
{
    if (checkdnsrr($domain))
        $result = shell_exec(escapeshellcmd($cmd ." ". $domain));
    else
        $result = 'DOMAIN IS NOT REGISTERED';

    return $result;
}

$cmd = get_cmd();
echo get_whois($cmd, 'google.com');

现在,是否有一种不同的方法可以轻松地让我提取域的到期日期,而不必拿出一大堆不同的正则表达式?因为每个域的信息格式都不同......

Here is my current code:

function get_cmd ()
{
    if (file_exists('/usr/local/bin/whois'))
        $cmd = '/usr/local/bin/whois';
    elseif (file_exists('/usr/bin/whois'))
        $cmd = '/usr/bin/whois';
    elseif (file_exists('/bin/whois'))
        $cmd = '/bin/whois';
    else
        die('whois shell command does not exist');

    return $cmd;
}

function get_whois ($cmd, $domain) 
{
    if (checkdnsrr($domain))
        $result = shell_exec(escapeshellcmd($cmd ." ". $domain));
    else
        $result = 'DOMAIN IS NOT REGISTERED';

    return $result;
}

$cmd = get_cmd();
echo get_whois($cmd, 'google.com');

now, is there a different method that will easily allow me to extract the expiration date of the domain without having to come up with a whole bunch of different regex? since the information will be formatted differently for every domain...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静若繁花 2024-11-25 22:03:28

我已经继续并为此使用了正则表达式。一些注册商甚至不在其 whois 中提供过期日期。

i've went ahead and just used regular expressions for this. some registrars don't even provide expiration dates in their whois.

若沐 2024-11-25 22:03:28

此代码将为您提供到期日期

<? 
$detail = "whois " . $_GET['domain']; 
$res = shell_exec($detail); 
$start = strpos($res,"Expiration"); 
echo substr($res,$start+16,11); 
?>

This code will give you the expiration date

<? 
$detail = "whois " . $_GET['domain']; 
$res = shell_exec($detail); 
$start = strpos($res,"Expiration"); 
echo substr($res,$start+16,11); 
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文