PHP to Ping an array of IPs
Posted: Mon Feb 20, 2006 7:59 pm
I've scoured the web for PHP code showing how to ping an array of IP addresses and have a bunch of good examples. However, none of the code allows me to ping IP addresses outside my server.
The following bare-bones code will only ping a domain name local to the server the PHP code is stored on. I would like to be able to ping a series of external public IP addresses (eg. 66.235.203.72) which I cannot do with the following code:
This works:
This does not work- says host is down when it is really up:
The following bare-bones code will only ping a domain name local to the server the PHP code is stored on. I would like to be able to ping a series of external public IP addresses (eg. 66.235.203.72) which I cannot do with the following code:
This works:
Code: Select all
<?php
$ip_address = "www.thehostgroup.com";
exec("ping -c 1 $ip_address", $out, $var);
if ($var == 0)
{
print "Host is up";
}
else
{
print "Host is down";
}
?>Code: Select all
<?php
$ip_address = "66.235.203.72";
exec("ping -c 1 $ip_address", $out, $var);
if ($var == 0)
{
print "Host is up";
}
else
{
print "Host is down";
}
?>