Net::Telnet::Trango - Perl extension for accessing the Trango telnet interface
use Net::Telnet::Trango; my $t = new Net::Telnet::Trango ( Timeout => 5 ); $t->open( Host => $ap ) or die "Error connecting: $!"; $t->login('password') or die "Couldn't log in: $!"; # Do whatever $t->exit; $t->close;
Perl access to the telnet interface on Trango APs and SUs.
A handy feature is that it will parse the output from certain commands that is in the format "[key1] value1 [key2] value2" and put those in a hashref that is returned. This makes using the output from things like sysinfo very easy to do.
None
new([Options from Net::Telnet,] [Decode => 0,]);
Same as new from Net::Telnet but sets the default Trango Prompt: '/[\$#]>\s*\Z/'
It also takes an optional parameter 'Decode'. If not defined it defaults to 1, if it is set to 0, it will not decode the output and instead return a reference to an array of the lines that were returned from the command.
These are usually only set internally.
Returns the firmware version if available, otherwise undef.
It should be available after a successful open().
returns the type of host from the login banner for example M5830S or M5300S.
Should be available after a successful open().
returns 1 when connected, undef otherwise.
returns 1 after a successful login(), 0 if it failed and undef if login() was never called.
returns the banner that is displayed when first connected at login. Only set after a successful open().
returns, as an array ref, the output from the last cmd() that was run.
returns the last error reported. Probably contains the last entry in last_lines.
Does the same as exit()
Does the same as reboot()
Does the same as save_ss()
Most of these are just shortcuts to cmd(String => METHOD), as such they accept the same options as cmd(). Specifically they take a named paramater "args", for example: tftpd(args => 'on') would enable tftpd
cmd(String => METHOD)
cmd()
tftpd(args => 'on')
Returns a hash ref of the decoded output from the command.
Also see enable_tftpd() and disable_tftpd() as those check that it was successfully changed.
exits the command session with the Trango and closes the connection
reboots the Trango and closes the connection
resets settings to default
Takes an optional argument, which sets the remarks. If there is no argument, returns the current remarks.
my $old_remarks = $t->remarks(); $t->remarks($new_remarks);
Returns an array ref of hashes containing each log line.
Returns true on success, undef on failure
Returns a hashref of the output from the syslog command
Returns the output from the pipe command
Returns the output from the maclist command
No useful output.
Returns the output from the eth link command
This command seems to cause some weird issues. It often will cause the command after it to appear to fail. I am not sure why.
Returns information about the SU.
You need to pass in the $suid and it will return the info for that suid.
$t->su_info($suid);
$t->su_testrflink($suid|'all');
Returns 1 on success, undef on failure.
$t->set_baseid($baseid);
$t->set_suid($baseid);
$t->set_defaultopmode(ap|su);
$t->opmode([ap y|su y]);
$channel = '11 v'; $t->freq([$channel]);
$channels = '11 v 11 h 12 v 12 h'; $t->freq_writescan($channels);
$channels = $t->freq_scantable(); # now $channels eq '11 v 11 h 12 v 12 h';
Calls Net::Telnet::open() then makes sure you get a password prompt so you are ready to login() and parses the login banner so you can get host_type() and firmware_version()
Calls open() if not already connected, then sends the password and sets logged_in() if successful
Takes a login banner (what you get when you first connect to the Trango) or reads what is already in login_banner() then parses it and sets host_type() and firmware_version() as well as login_banner()
linktest('suid'[, 'pkt len, bytes'[, '# of pkts'[, '# of cycles']]]);
Returns a hash reference to the results of the test
su_password('new_password'[, 'suid']) If no suid is specified, the default is "all".
$t->su_password('good_pass', 5);
ipconfig( 'new_ip', 'new_subnet', 'new_gateway' )
$t->ipconfig( '10.0.1.5', '255.255.255.0', '10.0.1.1' );
su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
$t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
returns a reference to an array of hashes each containing these keys 'suid', 'su2su', 'type', 'cir', 'mir' and 'mac'
Takes the following paramaters
suid : numeric, type : (reg|pr) cir : numeric, mir : numeric, mac : Almost any format, it will be reformatted,
and returns true on success or undef otherwise.
$t->sudb_add($suid, 'reg', $cir, $mir, $mac);
You should save_sudb() after calling this, or your changes will be lost when the AP is rebooted.
Takes either 'all' or the suid of the su to delete and returns true on success or undef otherwise.
$t->sudb_delete($suid);
Takes either the suid of the su to change as well as what you are changing, either "cir, mir or su2su" and returns true on success or undef otherwise.
cir and mir also take a value to set the cir/mir to.
su2su takes a group id parameter that is in hex.
$t->sudb_modify($suid, 'cir', 512);
runs tftpd(args => 'on') and makes sure that Tftpd is now 'listen'ing
runs tftpd(args => 'off') and makes sure that Tftpd is now 'disabled'
tftpd(args => 'off')
This does most of the work. At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango.
Normally returns the last lines from from the command
If you are using this, rather than one of the "easy" methods above, you probably want to read through the source of this module to see how some of the other commands are called.
In addition to the Net::Telnet::cmd() options, it also accepts these:
decode - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output
no_prompt - if this is true, it does not wait for a prompt, so you are not stuck waiting for something that will never happen.
cmd_disconnects - if this is true, it then sets logged_in() to false, then it will close() the connection and set is_connected() to false
expect - if this is set (usually to 'Success.') it will check for that in the last line of output and if it does not, will return undef because the command probably failed
args - a string containing the command line options that are passed to the command
$t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm
Net::Telnet
There are still a lot of commands that are not accessed directly. If you call them (as cmd("command + args") or whatever) and it works, please send me examples that work and I will try to get it incorporated into the next version of the script.
I also want to be able to parse the different types of output from commands like su, sudb all and anything else that would be better available as a perl datastructure.
Andrew Fresh <andrew@rraz.net>
You can find documentation for this module with the perldoc command.
perldoc Net::Telnet::Trango
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Net-Telnet-Trango
CPAN Ratings
http://cpanratings.perl.org/d/Net-Telnet-Trango
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango
Search CPAN
http://search.cpan.org/dist/Net-Telnet-Trango
Copyright (C) 2005,2006,2007 by Andrew Fresh
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Net::Telnet::Trango, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Telnet::Trango
CPAN shell
perl -MCPAN -e shell install Net::Telnet::Trango
For more information on module installation, please visit the detailed CPAN module installation guide.