Capture screen return from OLT CIANET equipment with PHP

Asked

Viewed 840 times

4

I am trying to capture data from an OLT CIANET via Telnet or SSH and I have not been successful, I want to know in which slot/UN is connected, the command to display the Onus I use is:

show port epon ".$slot."/1-4 onu mac ".$mac." epon-mac-address-table

I tried using an SSH class and another Telnet, I did not succeed in any of them, if someone has a telnet or ssh class, or example of how to send and capture those of the OLT, I thank you.

  • Already tried using the function exec()? the second argument is output text from the prompt.

  • I managed to solve using ssh2, but I confess that it was not legal, very difficult to capture the return data of the equipment...

  • Could you demonstrate how you did it? Other people might have the same problem.

  • yes, I’ll put the script:

  • Have you thought about using the exec() shell? I think it would be easier.

  • Unfortunately a simple shell exec would not meet the need, because it is an external machine, that is, it must be accessed and sent the commands to it remotely.

Show 1 more comment

1 answer

1

<?php
 // error_reporting(0);
 $slot = $_GET['slot'];
 $mac  = str_replace(":","",$_GET['mo']);

 $ip   = 'ip_do_equipamento_na_sua_rede';
 $user = 'seu_usuario';
 $pass = 'sua_senha_de_acesso';
 $porta = 'porta_do_socket';
 $cmd = "show port epon ".$slot."/1-4 onu mac '.$mac.' epon-mac-address-table";

 include('../Net/SSH2.php');

 $sftp = new Net_SSH2($ip,$porta);
 $sftp->login($usuario, $pass); 

 $sftp->write("enable\n");
 $sftp->write($cmd."\n");
 $saida = $sftp->read('port '.$slot.'/1');
 $sftp->write("exit\n");
 $saida = $sftp->read('exit');
 $sftp->disconnect();
 $bomba = explode(''.$slot.'/',$saida); // 
 $lin = count($bomba);

 $html = '<script type="text/javascript">'.PHP_EOL;
 for($i=0; $i<$lin; $i++) {
  $pedaco = $bomba[$i];
  $c4 = explode("\n", $pedaco);
  $contador = count($c4);
  $c4 = 1 + $i;
  if($contador > 3) {
   $html .= 'document.getElementById("fish'.$slot.''.$c4.'").innerHTML =
      "<font color=green>&#10004;</font>";';
  } else {
   $html .= 'document.getElementById("fish'.$slot.''.$c4.'").innerHTML =
      "<font color=red>&#10008;</font>";';
  }
 }
 $html .= '</script>'.PHP_EOL;
 echo $html;
 // echo '<pre>'.$html."</pre>";
?>
  • 1

    If you can explain why you used this approach it would be nice :)

  • I made this script lost, with the purpose of the user not need to look in the Fiber Service Areas Map, thus saving paper and time, and reducing errors once I check in the OLT the serial and the Onu mac.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.