我有一个循环,在其中循环多个域并 ping 主题:循环如下所示:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
}
我的问题:是否可以为每个循环域写出结果 IP 地址?
当然,只需使用gethostbyname(PHP 文档)。例子:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
echo gethostbyname($domain);
}
试试这个
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");