0

我有一个循环,在其中循环多个域并 ping 主题:循环如下所示:

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

}

我的问题:是否可以为每个循环域写出结果 IP 地址?

4

2 回答 2

2

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

foreach ($rows[1] as $domains){
   $domain='www.'.$domains;
   $output = shell_exec('ping -c1 '.$domain.'');
   echo "<pre>$output</pre>";
   echo gethostbyname($domain);
}
于 2012-05-30T21:19:04.963 回答
0

试试这个

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");
于 2012-05-30T21:21:39.570 回答