Reputation: 1034
I have a loop where I loop through a number of domains and I ping theme: the loop looks as follows:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
}
My question: is it possible to write out the resultant ip address for each looped domain?
Upvotes: 0
Views: 410
Reputation: 1636
try this
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");
Upvotes: 0
Reputation: 3348
Sure, just use gethostbyname (PHP docs). Example:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
echo gethostbyname($domain);
}
Upvotes: 2