Advertisement
edsheut

Extractor valores

May 19th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.18 KB | None | 0 0
  1. #!C://Perl64/bin/perl.exe
  2.  
  3. ##########INCLUDES##########
  4. use JSON; # imports encode_json, decode_json, to_json and from_json.
  5. use CGI qw(:standard); #WEB CGI
  6. use Net::Telnet;
  7.  
  8. ##########MAIN##########
  9. #TELNET
  10. my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die' );
  11. #GLOBALS
  12. my @portoutput;
  13. my $portoutput;
  14. #LOGIN
  15. $telnet->open('1.1.1.1');
  16. $telnet->waitfor('/login: $/i');
  17. $telnet->print('user');
  18. $telnet->waitfor('/password: $/i');
  19. $telnet->print('password');
  20. $telnet->waitfor('/user>/');
  21. #CHECK PORT
  22. $telnet->print('portstatsshow 1/1');
  23. @portoutput = $telnet->waitfor('/user>/');
  24. $portoutput = "@portoutput";
  25. #PARSE
  26. ($next_ftx, $next_frx) = Frames($portoutput);
  27. #CLOSE TELNET
  28. $telnet->close();
  29.  
  30. my $x = time*1000;
  31. #POINT ARRAY (X,TX,RX)
  32. my @array = ($x,$next_ftx,$next_frx);
  33. #JSON DATA
  34. my $json = encode_json \@array;
  35. print header('application/json');
  36. print $json;
  37.  
  38. ##########FUNCTIONS##########
  39. #PARSER
  40. sub Frames {
  41.     my ( $incomingtext ) = @_;
  42.     my @ftx;
  43.     my @frx;
  44.     $incomingtext =~ /(stat_ftx.*?)\n/s;
  45.     @ftx = split ' ', $1;  
  46.     $incomingtext =~ /(stat_frx.*?)\n/s;
  47.     @frx = split ' ', $1;
  48.     return int($ftx[1]), int($frx[1]);
  49. }
  50. ##########END##########
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement