I previously asked this question here on how to create a ping function and came up with the follow:
<?php
function pingAddress($ip) {
$pingresult = exec("ping -n 3 $ip", $outcome, $status);
if (1 != $status) {
$status = "alive";
} else {
$status = "dead";
}
echo "The IP address, $ip, is ".$status;
}
This had the desired results until I noticed that it was returning IP address 192.168.0.3 as alive when I knew it wasn't.
I checked through my standard windows command prompt and it was returning the following:
Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.
I'm assuming that the function think its alive due to the way its written and how it returns 'Reply from'? However I'm not too sure - can anyone shed some light on it?
Thanks