Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

miércoles, 25 de noviembre de 2015

Ping an IP address


  1. #!/usr/local/bin/php -q
  2. <?php
  3.   require('phpagi.php');
  4.  
  5.   $agi new AGI();
  6.  
  7.   $agi->answer();
  8.  
  9.  
  10.   // Play the "Enter the host you wish to ping, followed by the pound sign" prompt
  11.   // and then play the beep.   
  12.   $agi->stream_file('ping');
  13.   $result $agi->get_data('beep'300020);
  14.   $ip str_replace('*''.'$result['result']);
  15.  
  16.   /* Danger Will Robinson!  This does NOT properly escape the ping command!
  17.    * Someone could subvert your system if you don't fix this! - NO WARRANTY :P */
  18.   $execstr "/bin/ping -c 5 -q -w 9 $ip|grep transmitted";
  19.     
  20.   // be polite.
  21.   $agi->stream_file('thanks''#');
  22.     
  23.   $p popen($execstr'r');
  24.   if($p == FALSE)
  25.   {
  26.     $agi->text2wav("Failed to ping $ip");
  27.     $agi->conlog("Failed to ping $execstr");
  28.   }
  29.   else
  30.   {
  31.     $str '';
  32.     while(!feof($p))
  33.     {
  34.       $r fgets($p1024);
  35.       if(!$rbreak;
  36.       $str .= $r;
  37.     }
  38.  
  39.     // a minor hack.
  40.     $str str_replace('ms''milli-seconds'$str);
  41.     
  42.     // have festival read back the ping results.
  43.     $agi->text2wav("$ip - $str");
  44.   }
  45.  
  46.   $agi->hangup();
  47. ?>

http://phpagi.sourceforge.net/phpagi22/api-docs/

No hay comentarios:

Publicar un comentario