【发布时间】:2011-07-06 18:22:09
【问题描述】:
这是我当前的代码:
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');
现在,有没有一种不同的方法可以让我轻松提取域的到期日期,而不必想出一大堆不同的正则表达式?因为每个域的信息格式都会不同...
【问题讨论】:
-
大多数 WHOIS 响应将包含格式为
Expiration Date: 02-jun-2013的内容。当然你是对的,有几种不同的格式会弹出。你可能想看看这个问题:stackoverflow.com/questions/36817/who-provides-a-whois-api -
现在存在超过 1000 个 TLD,而且这个数字只会增加,这就是我停止尝试推出自己的解决方案并选择托管解决方案的原因。我开始使用 jsonwhoisapi.com,而不是为每个 TLD 编写解析器(因为它们中的大多数格式不同,即使只是略有不同)。在他们的免费套餐中,每月有 10,000 个请求,因此对于我的小型网站来说仍然是免费的..
-
不,不要运行 whois 命令,使用编程语言中的库或在端口 43 上打开 TCP 套接字,请参阅 RFC3912