How to ping an IP with PHP 08-10-2015, 07:39 PM
#1
Well not sure if this is at all useful to anyone here but you can ping an IP via PHP and it's all pretty simple really. Just a small portion of code and it's done. You can adjust this so it sends multiple pings but I won't post that version unless people actually find this one interesting.
So here we go.
The output of the above PHP code is like shown below.
output looks like below
So here we go.
Code:
<?php
$ip = "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
?>The output of the above PHP code is like shown below.
output looks like below
Code:
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
)



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)



