Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!C://Perl64/bin/perl.exe
- ##########INCLUDES##########
- use JSON; # imports encode_json, decode_json, to_json and from_json.
- use CGI qw(:standard); #WEB CGI
- use Net::Telnet;
- ##########MAIN##########
- #TELNET
- my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die' );
- #GLOBALS
- my @portoutput;
- my $portoutput;
- #LOGIN
- $telnet->open('1.1.1.1');
- $telnet->waitfor('/login: $/i');
- $telnet->print('user');
- $telnet->waitfor('/password: $/i');
- $telnet->print('password');
- $telnet->waitfor('/user>/');
- #CHECK PORT
- $telnet->print('portstatsshow 1/1');
- @portoutput = $telnet->waitfor('/user>/');
- $portoutput = "@portoutput";
- #PARSE
- ($next_ftx, $next_frx) = Frames($portoutput);
- #CLOSE TELNET
- $telnet->close();
- my $x = time*1000;
- #POINT ARRAY (X,TX,RX)
- my @array = ($x,$next_ftx,$next_frx);
- #JSON DATA
- my $json = encode_json \@array;
- print header('application/json');
- print $json;
- ##########FUNCTIONS##########
- #PARSER
- sub Frames {
- my ( $incomingtext ) = @_;
- my @ftx;
- my @frx;
- $incomingtext =~ /(stat_ftx.*?)\n/s;
- @ftx = split ' ', $1;
- $incomingtext =~ /(stat_frx.*?)\n/s;
- @frx = split ' ', $1;
- return int($ftx[1]), int($frx[1]);
- }
- ##########END##########
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement