I want to ask is any php script available which is able to ping an IP Address if is it so let me know how we can do that ...?
Asked
Active
Viewed 1,377 times
-1
-
duplicate of http://stackoverflow.com/questions/8030789/pinging-an-ip-address-using-php-and-echoing-the-result – Ravi Kumar Apr 13 '17 at 06:04
-
Every 30 seconds? Even when there's no incoming request? Are you sure you want to do this in PHP? – apokryfos Apr 13 '17 at 06:25
2 Answers
0
$ip = "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
Output will be an Array. Something like this:
Array
(
[0] =>
[1] => Pinging 127.0.0.1 with 32 bytes of data:
[2] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
[3] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
[4] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
[5] =>
[6] => Ping statistics for 127.0.0.1:
[7] => Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
[8] => Approximate round trip times in milli-seconds:
[9] => Minimum = 0ms, Maximum = 0ms, Average = 0ms
)

haMzox
- 2,073
- 1
- 12
- 25
0
On linux, you the use the following :
<?php
function ping($ip) {
$result = exec("/bin/ping -n 3 $ip", $outcome, $status);
if (0 == $status) {
$status = "alive";
} else {
$status = "dead";
}
echo $status;
}
ping("80.80.80.80");
?>

mrid
- 5,782
- 5
- 28
- 71