Page 1 of 1

PHP to Ping an array of IPs

Posted: Mon Feb 20, 2006 7:59 pm
by jat32
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:

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";
}
?>
This does not work- says host is down when it is really up:

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";
}
?>

Posted: Mon Feb 20, 2006 8:34 pm
by josh
Works fine for me

Code: Select all

# ping -c 1 66.235.203.72
PING 66.235.203.72 (66.235.203.72) 56(84) bytes of data.
64 bytes from 66.235.203.72: icmp_seq=0 ttl=50 time=79.4 ms

--- 66.235.203.72 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 79.470/79.470/79.470/0.000 ms, pipe 2

Posted: Mon Feb 20, 2006 10:45 pm
by Benjamin
Dubious

Posted: Tue Feb 21, 2006 2:58 am
by Chris Corbyn
Are you using Linux or windows? That looks like it should work fine on a *nix server.