通过PHP获取域名到期日期

时间:2011-07-06 18:22:10

标签: php dns whois

这是我目前的代码:

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');

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

2 个答案:

答案 0 :(得分:0)

我已经开始使用正则表达式。有些注册商甚至没有提供过期日期。

答案 1 :(得分:0)

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

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