Php ping域并在csv文件中写出ip

Php ping域并在csv文件中写出ip,php,ping,Php,Ping,我有一个循环,其中我循环了许多域和I ping主题:循环如下所示: foreach ($rows[1] as $domains){ $domain='www.'.$domains; $output = shell_exec('ping -c1 '.$domain.''); echo "<pre>$output</pre>"; } foreach($rows[1]作为$domains){ $domain='www.'.$domains; $output=shell_ex

我有一个循环,其中我循环了许多域和I ping主题:循环如下所示:

foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";

}
foreach($rows[1]作为$domains){
$domain='www.'.$domains;
$output=shell_exec('ping-c1'.$domain'.');
回显“$output”;
}
我的问题:是否可以写出每个循环域的结果ip地址?

当然,只需使用(PHP文档)。例如:

foreach ($rows[1] as $domains){
    $domain='www.'.$domains;
    $ip = gethostbyname($domain);
    echo $domain.','.$ip.'\n';
}

//OUPUT HEADERS
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=domains.csv;" );
header("Content-Transfer-Encoding: binary");
foreach($rows[1]作为$domains){
$domain='www.'.$domains;
$output=shell_exec('ping-c1'.$domain'.');
回显“$output”;
echo gethostbyname($domain);
}
试试这个


由于ping的输出取决于您的操作系统,出于好奇,我建议您使用gethostbyname(),您希望通过在一系列域中ping“www”主机名来了解什么?您知道这可能不是最好的方法,我仍在学习新的东西,我们的主机有很多域名,我想在从主机上抓取域名html表后,自动化一点程序,以了解ip是我们的还是域名已经被出售,因为不幸的是,这种事情还没有更新。谢谢你纠正我的语法。
foreach ($rows[1] as $domains){
    $domain='www.'.$domains;
    $ip = gethostbyname($domain);
    echo $domain.','.$ip.'\n';
}

//OUPUT HEADERS
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=domains.csv;" );
header("Content-Transfer-Encoding: binary");