$ip = '192.168.0.1';
$ping = ping($ip);
if(!$ping) echo 'Ping timed out.'; else
echo 'ping time: ' . $ping . ' ms';
function ping($ip) {
echo 'IP: '. $ip . '<hr>';
$result = `ping -c 1 $ip`;
$a = strpos($result, "time=");
$b = strpos($result, " ms");
if (!$a || !$b) {
return FALSE;
}
$a = $a+5;
$r = substr($result, $a, $b-$a);
return $r;
}
I got this code from these forums. If you run this little code from the linux shell prompt, it works flawlessly...if you run it from a browser window, it always reports the IP as "timed out". Anyone have any ideas why it's doing this?