Ping in PHP + Apache2 Debian

0

Good morning,

I was able to search the internet to do the script below as what I needed, but I still lack a detail, so I dribble in a machine, as I could do to be a list of machines, without my having to repeat the commands for each machine?

My idea would even be to do this integration with mysql database, which would give a select one by bringing the ip's registered there.

Follow the code:

<html>
<head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <META HTTP-EQUIV="REFRESH" CONTENT="5">

        <title>PAINEL DE MONITORAMENTO</title>

        <link rel="stylesheet" href="bootstrap/simplex/style.css">
        <link rel="stylesheet" href="bootstrap/simplex/bootstrap.min.css">
        <link rel="stylesheet" href="bootstrap/css/datatables.css">
        <script src="bootstrap/js/jquery.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script src="bootstrap/js/jquery.dataTables.min.js"></script>
        <script src="bootstrap/js/datatables.js"></script>
</head>
<body>
<div class='container'>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">PAINEL DE MONITORAMENTO   |</a>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"></a></li>
      </ul>
    </div>
  </div>
</nav>
<div><a href="#"></a><img src="on.png" alt="ATIVO">  ATIVO
     <a href="#"></a><img src="off.png" alt="INATIVO">  INATIVO</div>
 <br>
 <?php
function ping($host)
{
        exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
        return $rval === 0;
}

$host = '192.168.0.77';
$up = ping($host);
?>
<div class"container">
    <div class="row">
     <div class="col-md-4"> 
        <?php
         echo"<div class='list-group'>";
           echo"<a href='#' class='list-group-item active'>IP: $host </a>";
           echo"<a href='#' class='list-group-item'>NOME:</a>"; 
           echo'<a href="#"  class="list-group-item">STATUS: <img src="'.($up ? 'on' : 'off').'.png" alt="'.($up ? 'up' : 'down').'" /></a>';
         echo"</div>";
         echo "<br/>";
         ?>
     </div>
     <div class="col-md-4"> 
        <?php
         echo"<div class='list-group'>";
           echo"<a href='#' class='list-group-item active'>IP: $host </a>";
           echo"<a href='#' class='list-group-item'>NOME:</a>"; 
           echo'<a href="#"  class="list-group-item">STATUS: <img src="'.($up ? 'on' : 'off').'.png" alt="'.($up ? 'up' : 'down').'" /></a>';
         echo"</div>";
         echo "<br/>";
         ?>
     </div>
     <div class="col-md-4">
        <?php
         echo"<div class='list-group'>";
           echo"<a href='#' class='list-group-item active'>IP: $host </a>";
           echo"<a href='#' class='list-group-item'>NOME:</a>"; 
           echo'<a href="#"  class="list-group-item">STATUS: <img src="'.($up ? 'on' : 'off').'.png" alt="'.($up ? 'up' : 'down').'" /></a>';
         echo"</div>";
         echo "<br/>";
         ?>
     </div>
   </div>
  <br>
</body>
</html>

@rray:   I've done this for more while bringing only the first result, I could see if I'm doing something wrong:

<?php
require_once('conexao.php'); 
  $result = mysql_query("SELECT srv_ip AS IP, srv_nome AS NOME_SERVIDOR FROM servidores");
   if (!$result) {
    echo 'Não foi possível executar a consulta: ' . mysql_error();
    exit;
   }
    while ($row = mysql_fetch_array($result)) {
      $srv_ip    = $row["IP"];
      $srv_name  = $row["NOME_SERVIDOR"];


function ping($host)
{
        exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
        return $rval === 0;
}

$host = $srv_ip;
$up = ping($host);

echo "<div class'container'>";
     echo "<div class='row'>";
       echo "<div class='col-md-4'> ";
         echo"<div class='list-group'>";
           echo"<a href='#' class='list-group-item active'>IP: $host </a>";
           echo"<a href='#' class='list-group-item'>NOME:$host</a>"; 
           echo'<a href="#"  class="list-group-item">STATUS: <img src="'.($up ? 'on' : 'off').'.png" alt="'.($up ? 'up' : 'down').'" /></a>';
          echo"</div>";
         echo "<br/>";
        echo "</div>";
         }
     ?>
    
asked by anonymous 07.03.2016 / 14:05

0 answers