Possible Duplicate:
Pinging an IP address using PHP and echoing the result
How do you ping an ip addresses in php. and give the the results as if you are on cmd program in windows
<?php
system(‘ping -c 192.168.0.104’); // Ping IP address.<br>
echo “pinged”;<br>
?>
Use the command "ping 192.168. 1.101 -t" to initiate a continuous ping. Again, replace the IP address with one specific to your device as needed. The -t can be placed before or after the IP address.
Let's call it "servers. txt" and save it (as you going to ping server names so make sure name resolution is happening). Next, open Command Prompt and navigate to the folder where you just created the file in which you listed the name of servers. This will attempt to ping every system in the list and return the result.
While the ping command is used to ping a single host device to identify its existence, ping sweep helps to ping multiple IP addresses simultaneously. It's a basic network scanning technique used to determine the range of active and inactive IP addresses available on the network.
Try this
$host="192.168.0.104";
exec("ping -c 4 " . $host, $output, $result);
print_r($output);
if ($result == 0)
echo "Ping successful!";
else
echo "Ping unsuccessful!";
Note: This is dependant on the OS you are running. Windows will default to only 4 pings while Linux will ping forever.
To ping twice in Windows, use "ping -n 2 host"
To ping twice in Linux, use "ping -c 2 host"
$ip = "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
output looks like below
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With