On my Ubuntu system, the command ls -l /bin/ping
shows:
-rwsr-xr-x 1 root root 34716 2010-11-15 09:08 /bin/ping
This means that although "ping" is owned by root, all users can execute it.
You should try with the following PHP code:
<html>
<body>
<pre>
<?php
$result = exec("/bin/ping -c 1 -W 1 127.0.0.1");
echo "result=".$result."
";
?>
</pre>
</body>
</html>
Obviuously, you should replace "127.0.0.1" with a valid IP address for your network.
The -c 1
option stops pinging after sending one packet, as described in the manual page:
-c count
Stop after sending count ECHO_REQUEST packets.
With deadline option, ping waits for count ECHO_REPLY packets, until the timeout
expires.
The -W 1
option forces ping to stop if it does not get a response after one second:
-W timeout
Time to wait for a response, in seconds.
The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.