18 lines
417 B
PHP
18 lines
417 B
PHP
<?php
|
|
|
|
$host = "10.1.1.2";
|
|
echo json_encode(ping($host));
|
|
|
|
function ping($host) {
|
|
$command = "ping -c 4 " . escapeshellarg($host);
|
|
$output = [];
|
|
exec($command, $output, $status);
|
|
|
|
// Check if the ping was successful
|
|
if ($status == 0) {
|
|
return ['status' => 'online', 'output' => $output];
|
|
} else {
|
|
return ['status' => 'offline', 'output' => $output];
|
|
}
|
|
}
|
|
?>
|