使用PHP获取DNS管理员


Get DNS-Admin with PHP

http://toolbar.netcraft.com/site_report?url=www.example.com,你会得到一个"DNS管理员"。如何从php脚本中请求这些信息?

最好的选择可能是直接获取dns记录:

<?php
$result = dns_get_record("example.com", DNS_SOA);
$admin = preg_replace('/'./', '@', $result[0]['rname'], 1); //need to replace the first dot with "@" because the rname is passed with dots and doesn't include "@"
echo $admin; //will output hostmaster@icann.org
?>

阅读php的dns_get_record函数。

Netcraft拥有格式良好的数据,他们很可能从DNS记录中提取这些数据。不幸的是,DNS记录本身并不那么规则(或者不需要Netcraft)。

你所做的听起来有点邪恶,但也许可以尝试使用像whois这样的系统命令,然后搜索电子邮件地址。

<?php 
$domain = 'cnn.com';
$results = shell_exec( "whois {$domain}" );
//parse results here
?>

d每当你想用php抓取内容时,cURL就是你的朋友。

下面的简单用法示例:

<?php
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://example.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
    print "Unable to fetch data.";
}
else
{
    print $buffer;
}
?>

当然,您将需要解析提取的结果,并提取您需要的任何内容。

希望有帮助,祝你好运!

更新:不确定操作是想从网页获取结果,还是直接从dns查询工具(dig、whois等)获取结果。如果我理解错误,这篇文章将被删除。