Here we go... if you use windows and have english, then you can use something like below. Worked on my windows XP ( swedish, so I had to replace "time" with "tid", but anyway. .) )
According to the article the ping command is a bit different on bsd/linux, so I post that code below too (although I've not tested it myself).
It does pretty much exactly what you want, so hope you get it working. =)
/Anders
<?php
//windows
function ping($host) {
$ip=gethostbyname($host);
$result=ping -n 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;
}
if( ping( 'google.com' ) )
{
echo "host online!";
}
else
{
echo "host offline!";
}
?>
BSD/Linux?/AnyX???
//bsd
function ping($host) {
$ip=gethostbyname($host);
$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;
}