.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Cisco 3pm" .TH Cisco 3pm "2023-09-14" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::Telnet::Cisco \- interact with a Cisco router .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::Telnet::Cisco; \& \& my $session = Net::Telnet::Cisco\->new(Host => \*(Aq123.123.123.123\*(Aq); \& $session\->login(\*(Aqlogin\*(Aq, \*(Aqpassword\*(Aq); \& \& # Execute a command \& my @output = $session\->cmd(\*(Aqshow version\*(Aq); \& print @output; \& \& # Enable mode \& if ($session\->enable("enable_password") ) { \& @output = $session\->cmd(\*(Aqshow privilege\*(Aq); \& print "My privileges: @output\en"; \& } else { \& warn "Can\*(Aqt enable: " . $session\->errmsg; \& } \& \& $session\->close; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Net::Telnet::Cisco provides additional functionality to Net::Telnet for dealing with Cisco routers. .PP \&\fBcmd()\fR parses router-generated error messages \- the kind that begin with a '%' \- and stows them in \f(CW$obj\fR\->\fBerrmsg()\fR, so that errmode can be used to perform automatic error-handling actions. .SH "CAVEATS" .IX Header "CAVEATS" Before you use Net::Telnet::Cisco, you should have a good understanding of Net::Telnet, so read it's documentation first, and then come back here to see the improvements. .PP Some things are easier to accomplish with \s-1UCD\s0's C\-based \s-1SNMP\s0 module, or the all-perl Net::SNMP. \s-1SNMP\s0 has three advantages: it's faster, handles errors better, and doesn't use any VTYs on the router. \s-1SNMP\s0 does have some limitations, so for anything you can't accomplish with \&\s-1SNMP,\s0 there's Net::Telnet::Cisco. .SH "METHODS" .IX Header "METHODS" .IP "\fBnew\fR \- create new Net::Telnet::Cisco object" 4 .IX Item "new - create new Net::Telnet::Cisco object" .Vb 10 \& $session = Net::Telnet::Cisco\->new( \& [Autopage => $boolean,] # 1 \& [More_prompt => $matchop,] # \*(Aq/(?m:^[\es\e0]*\-\-More\-\-)/\*(Aq, \& [Always_waitfor_prompt => $boolean,] # 1 \& [Waitfor_pause => $milliseconds,] # 0.1 \& [Normalize_cmd => $boolean,] # 1 \& [Send_wakeup => $when,] # 0 \& [Ignore_warnings => $boolean,] # 0 \& [Warnings => $matchop,] # see docs \& [Errors => $matchop,] # see docs \& \& # Net::Telnet arguments \& [Binmode => $mode,] \& [Cmd_remove_mode => $mode,] \& [Dump_Log => $filename,] \& [Errmode => $errmode,] \& [Fhopen => $filehandle,] \& [Host => $host,] \& [Input_log = => $file,] \& [Input_record_separator => $chars,] \& [Option_log => $file,] \& [Ors = => $chars,] \& [Output_log => $file,] \& [Output_record_separator => $chars,] \& [Port => $port,] \& [Prompt = => $matchop,] # see docs \& [Rs => $chars,] \& [Telnetmode => $mode,] \& [Timeout => $secs,]); \& ); .Ve .Sp Creates a new object. Read `perldoc perlboot` if you don't understand that. .IP "\fBlogin\fR \- login to a router" 4 .IX Item "login - login to a router" .Vb 1 \& $ok = $obj\->login($username, $password); \& \& $ok = $obj\->login([Name => $username,] \& [Password => $password,] \& [Passcode => $passcode,] # for Secur\-ID/XTACACS \& [Prompt => $match,] \& [Timeout => $secs,]); .Ve .Sp All arguments are optional as of v1.05. Some routers don't ask for a username, they start the login conversation with a password request. .IP "\fBcmd\fR \- send a command" 4 .IX Item "cmd - send a command" .Vb 11 \& $ok = $obj\->cmd($string); \& $ok = $obj\->cmd(String => $string, \& [Output => $ref,] \& [Cmd_remove_mode => $mode,] \& [Errmode => $mode,] \& [Input_record_separator => $chars,] \& [Ors => $chars,] \& [Output_record_separator => $chars,] \& [Prompt => $match,] \& [Rs => $chars,] \& [Timeout => $secs,]); \& \& @output = $obj\->cmd($string); \& @output = $obj\->cmd(String => $string, \& [Output => $ref,] \& [Cmd_remove_mode => $mode,] \& [Errmode => $mode,] \& [Input_record_separator => $chars,] \& [Ors => $chars,] \& [Output_record_separator => $chars,] \& [Prompt => $match,] \& [Rs => $chars,] \& [Timeout => $secs,]); .Ve .Sp Normalize_cmd has been added to the default Net::Telnet args. It lets you temporarily change whether backspace, delete, and kill characters are parsed in the command output. (This is performed by default) .IP "\fBprompt\fR \- return control to the program whenever this string occurs in router output" 4 .IX Item "prompt - return control to the program whenever this string occurs in router output" .Vb 1 \& $matchop = $obj\->prompt; \& \& $prev = $obj\->prompt($matchop); .Ve .Sp The default cmd_prompt changed in v1.05. It's suitable for matching prompts like \f(CW\*(C`router$ \*(C'\fR, \f(CW\*(C`router# \*(C'\fR, \f(CW\*(C`router> (enable) \*(C'\fR, and \f(CW\*(C`router(config\-if)# \*(C'\fR .Sp Let's take a closer look, shall we? .Sp .Vb 3 \& (?m: # Net::Telnet doesn\*(Aqt accept quoted regexen (i.e. qr//) \& # so we need to use an embedded pattern\-match modifier \& # to treat the input as a multiline buffer. \& \& ^ # beginning of line \& \& \er? # optional linefeed \& \& [\ew.\-]+ # router hostname \& \& \es? # optional space \& \& (?: # Strings like "(config)" and "(config\-if)", "(config\-line)", \& # and "(config\-router)" indicate that we\*(Aqre in privileged \& \e(config[^\e)]*\e) # EXEC mode (i.e. we\*(Aqre enabled). \& )? # The middle backslash is only there to appear my syntax \& # highlighter. \& \& \es? # more optional space \& \& [\e$#>] # Prompts typically end with "$", "#", or ">". Backslash \& # for syntax\-highlighter. \& \& \es? # more space padding \& \& (?: # Catalyst switches print "(enable)" when in privileged \& \e(enable\e) # EXEC mode. \& )? \& \& \es* # spaces before the end\-of\-line aren\*(Aqt important to us. \& \& $ # end of line \& \& ) # end of (?m: .Ve .Sp The default prompt published in 1.03 was \&\f(CW\*(C`/^\es*[\ew().\-]*[\e$#>]\es?(?:\e(enable\e))?\es*$/\*(C'\fR. As you can see, the prompt was drastically overhauled in 1.05. If your code suddenly starts timing out after upgrading Net::Telnet::Cisco, this is the first thing to investigate. .IP "\fBenable\fR \- enter enabled mode" 4 .IX Item "enable - enter enabled mode" .Vb 1 \& $ok = $obj\->enable; \& \& $ok = $obj\->enable($password); \& \& $ok = $obj\->enable( \& [Name => $name,] \& [Password => $password,] \& [Passcode => $passcode,] \& [Level => $level,] \& ); .Ve .Sp This method changes privilege level to enabled mode, (i.e. root) .Sp If a single argument is provided by the caller, it will be used as a password. For more control, including the ability to set the privilege-level, you must use the named-argument scheme. .Sp \&\fBenable()\fR returns 1 on success and undef on failure. .IP "\fBis_enabled\fR \- Am I root?" 4 .IX Item "is_enabled - Am I root?" .Vb 1 \& $bool = $obj\->is_enabled; .Ve .Sp A trivial check to see whether we have a root-style prompt, with either the word \*(L"(enable)\*(R" in it, or a trailing \*(L"#\*(R". .Sp \&\fBWarning\fR: this method will return false positives if your prompt has \&\*(L"#\*(R"s in it. You may be better off calling \f(CW\*(C`$obj\->cmd("show privilege")\*(C'\fR instead. .IP "\fBdisable\fR \- leave enabled mode" 4 .IX Item "disable - leave enabled mode" .Vb 1 \& $ok = $obj\->disable; .Ve .Sp This method exits the router's privileged mode. .IP "\fBios_break\fR \- send a break (control\-^)" 4 .IX Item "ios_break - send a break (control-^)" .Vb 1 \& $ok = $obj\->ios_break( [ additional strings to print, ... ] ); .Ve .Sp You may have to use \fBerrmode()\fR, fork, or threads to break at the an appropriate time. .IP "\fBlast_prompt\fR \- displays the last prompt matched by \fBprompt()\fR" 4 .IX Item "last_prompt - displays the last prompt matched by prompt()" .Vb 1 \& $match = $obj\->last_prompt; .Ve .Sp \&\fBlast_prompt()\fR will return '' if the program has not yet matched a prompt. .IP "\fBalways_waitfor_prompt\fR \- waitfor and cmd prompt behaviour" 4 .IX Item "always_waitfor_prompt - waitfor and cmd prompt behaviour" .Vb 1 \& $boolean = $obj\->always_waitfor_prompt; \& \& $boolean = $obj\->always_waitfor_prompt($boolean); .Ve .Sp Default value: 1 .Sp If you pass a Prompt argument to \fBcmd()\fR or \fBwaitfor()\fR a String or Match, they will return control on a successful match of your argument(s) or the default prompt. Set always_waitfor_prompt to 0 to return control only for your arguments. .Sp This method has no effect on \fBlogin()\fR. \fBlogin()\fR will always wait for a prompt. .IP "\fBwaitfor_pause\fR \- insert a small delay before \fBwaitfor()\fR" 4 .IX Item "waitfor_pause - insert a small delay before waitfor()" .Vb 1 \& $boolean = $obj\->waitfor_pause; \& \& $boolean = $obj\->waitfor_pause($milliseconds); .Ve .Sp Default value: 0.1 .Sp In rare circumstances, the last_prompt is set incorrectly. By adding a very small delay before calling the parent class's \fBwaitfor()\fR, this bug is eliminated. If you ever find reason to modify this from it's default setting, please let me know. .IP "\fBautopage\fR \- Turn autopaging on and off" 4 .IX Item "autopage - Turn autopaging on and off" .Vb 1 \& $boolean = $obj\->autopage; \& \& $boolean = $obj\->autopage($boolean); .Ve .Sp Default value: 1 .Sp \&\s-1IOS\s0 pages output by default. It expects human eyes to be reading the output, not programs. Humans hit the spacebar to scroll page by page so \fBautopage()\fR mimicks that behaviour. This is the slow way to handle paging. See the Paging \s-1EXAMPLE\s0 for a faster way. .IP "\fBnormalize_cmd\fR \- Turn normalization on and off" 4 .IX Item "normalize_cmd - Turn normalization on and off" .Vb 1 \& $boolean = $obj\->normalize_cmd; \& \& $boolean = $obj\->normalize_cmd($boolean); .Ve .Sp Default value: 1 .Sp \&\s-1IOS\s0 clears '\-\-More\-\-' prompts with backspaces (e.g. ^H). If you're excited by the thought of having raw control characters like ^H (backspace), ^? (delete), and ^U (kill) in your command output, turn this feature off. .Sp Logging is unaffected by this setting. .IP "\fBmore_prompt\fR \- Matchop used by \fBautopage()\fR" 4 .IX Item "more_prompt - Matchop used by autopage()" .Vb 1 \& $matchop = $obj\->prompt; \& \& $prev = $obj\->prompt($matchop); .Ve .Sp Default value: '/(?m:^(?:[\es\e0]*\-\-More\-\-)/', .Sp Please email me if you find others. .IP "\fBsend_wakeup\fR \- send a newline to the router at login time" 4 .IX Item "send_wakeup - send a newline to the router at login time" .Vb 1 \& $when = $obj\->send_wakeup; \& \& $when = $obj\->send_wakeup( \*(Aqconnect\*(Aq ); \& $when = $obj\->send_wakeup( \*(Aqtimeout\*(Aq ); \& $when = $obj\->send_wakeup( 0 ); .Ve .Sp Default value: 0 .Sp Some routers quietly allow you to connect but don't display the expected login prompts. Sends a newline in the hopes that this spurs the routers to print something. .Sp \&'connect' sends a newline immediately upon connection. \&'timeout' sends a newline if the connection timeouts. 0 turns this feature off. .Sp I understand this works with Livingston Portmasters. .IP "\fBignore_warnings\fR \- Don't call \fBerror()\fR for warnings" 4 .IX Item "ignore_warnings - Don't call error() for warnings" .Vb 1 \& $boolean = $obj\->ignore_warnings; \& \& $boolean = $obj\->ignore_warnings($boolean); .Ve .Sp Default value: 0 .Sp Not all strings that begin with a '%' are really errors. Some are just warnings. By setting this, you are ignoring them. This will show up in the logs, but that's it. .IP "\fBwarnings\fR \- Matchop used by \fBignore_warnings()\fR." 4 .IX Item "warnings - Matchop used by ignore_warnings()." .Vb 1 \& $boolean = $obj\->warnings; \& \& $boolean = $obj\->warnings($matchop); .Ve .Sp Default value: .Sp .Vb 7 \& \*(Aq/(?mx:^%\es?Unknown\e VPN \& |^%\es?IP\e routing\e table\e VRF.*\e does\e not\e exist\e.\e Create\e first$ \& |^%\es?No\e CEF\e interface\e information \& |^%\es?No\e matching\e route\e to\e delete$ \& |^%\es?Not\e all\e config\e may\e be\e removed\e and\e may\e reappear\e after\e reactivating \& |^%\es?Warning: \& )/\*(Aq, .Ve .Sp Not all strings that begin with a '%' are really errors. Some are just warnings. Cisco calls these the CIPMIOSWarningExpressions. .IP "\fBerrors\fR \- Matchop used to catch special-cased errors." 4 .IX Item "errors - Matchop used to catch special-cased errors." .Vb 1 \& $boolean = $obj\->errors; \& \& $boolean = $obj\->errors($matchop); .Ve .Sp Default value: .Sp .Vb 1 \& \*(Aq/(?mx:^Unknown\e command\e "[^\e"]*"\e Use\e \e\*(Aqhelp\e\*(Aq\e for\e more\e info\e.)/\*(Aq, .Ve .Sp Some errors don't begin with a '%'. Trap them here. .SH "EXAMPLES" .IX Header "EXAMPLES" .SS "Paging" .IX Subsection "Paging" v1.08 added internal autopaging support to \fBcmd()\fR. Whenever a '\-\-Page\-\-' prompt appears on the screen, we send a space right back. It works, but it's slow. You'd be better off sending one of the following commands just after \fBlogin()\fR: .PP .Vb 2 \& # To a router \& $session\->cmd(\*(Aqterminal length 0\*(Aq); \& \& # To a switch \& $session\->cmd(\*(Aqset length 0\*(Aq); .Ve .SS "Logging" .IX Subsection "Logging" Want to see the session transcript? Just call \fBinput_log()\fR. .PP .Vb 4 \& e.g. \& my $session = Net::Telnet::Cisco\->new(Host => $router, \& Input_log => "input.log", \& ); .Ve .PP See \fBinput_log()\fR in Net::Telnet for info. .PP Input logs are easy-to-read translated transcripts with all of the control characters and telnet escapes cleaned up. If you want to view the raw session, see \fBdump_log()\fR in Net::Telnet. If you're getting tricky and using \fBprint()\fR in addition to \fBcmd()\fR, you may also want to use \&\fBoutput_log()\fR. .SS "Big output" .IX Subsection "Big output" Trying to dump the entire \s-1BGP\s0 table? (e.g. \*(L"show ip bgp\*(R") The default buffer size is 1MB, so you'll have to increase it. .PP .Vb 2 \& my $MB = 1024 * 1024; \& $session\->max_buffer_length(5 * $MB); .Ve .SS "Sending multiple lines at once" .IX Subsection "Sending multiple lines at once" Some commands like \*(L"extended ping\*(R" and \*(L"copy\*(R" prompt for several lines of data. It's not necessary to change the prompt for each line. Instead, send everything at once, separated by newlines. .PP For: .PP .Vb 8 \& router# ping \& Protocol [ip]: \& Target IP address: 10.0.0.1 \& Repeat count [5]: 10 \& Datagram size [100]: 1500 \& Timeout in seconds [2]: \& Extended commands [n]: \& Sweep range of sizes [n]: .Ve .PP Try this: .PP .Vb 7 \& my $protocol = \*(Aq\*(Aq; # default value \& my $ip = \*(Aq10.0.0.1\*(Aq; \& my $repeat = 10; \& my $datagram = 1500; \& my $timeout = \*(Aq\*(Aq; # default value \& my $extended = \*(Aq\*(Aq; # default value \& my $sweep = \*(Aq\*(Aq; # default value \& \& $session\->cmd( \& "ping \& $protocol \& $ip \& $repeat \& $datagram \& $timeout \& $extended \& $sweep \& "); .Ve .PP If you prefer, you can put the cmd on a single line and replace every static newline with the \*(L"\en\*(R" character. .PP e.g. .PP .Vb 2 \& $session\->cmd("ping\en$protocol\en$ip\en$repeat\en$datagram\en" \& . "$timeout\en$extended\en$sweep\en"); .Ve .SS "Backup via \s-1TFTP\s0" .IX Subsection "Backup via TFTP" Backs up the running-confg to a \s-1TFTP\s0 server. Backup file is in the form \*(L"router-confg\*(R". Make sure that file exists on the \s-1TFTP\s0 server or the transfer will fail! .PP .Vb 4 \& my $backup_host = "tftpserver.somewhere.net"; \& my $device = "cisco.somewhere.net"; \& my $type = "router"; # or "switch"; \& my $ios_version = 12; \& \& my @out; \& if ($type eq "router") { \& if ($ios_version >= 12) { \& @out = $session\->cmd("copy system:/running\-config " \& . "tftp://$backup_host/$device\-confg\en\en\en"); \& } elsif ($ios_version >= 11) { \& @out = $session\->cmd("copy running\-config tftp\en$backup_host\en" \& . "$device\-confg\en"); \& } elsif ($ios_version >= 10) { \& @out = $session\->cmd("write net\en$backup_host\en$device\-confg\en\en"); \& } \& } elsif ($type eq "switch") { \& @out = $session\->cmd("copy system:/running\-config " \& . "tftp://$backup_host/$device\-confg\en\en\en"); \& } .Ve .SS "Sending control characters" .IX Subsection "Sending control characters" Use \fBprint()\fR if you expect to get a prompt back. Use \fBcmd()\fR if you don't. .PP .Vb 2 \& $session\->print("\ec^"); # send control\-^ \& $session\->cmd("\ecZ"); # send control\-Z .Ve .PP See also: \f(CW\*(C`ios_break()\*(C'\fR .SH "SUPPORT" .IX Header "SUPPORT" http://NetTelnetCisco.sourceforge.net/ .SS "Mailing lists" .IX Subsection "Mailing lists" \&\fInettelnetcisco-announce\fR is for important security bulletins and upgrades. Very low traffic, no spam, \fB\s-1HIGHLY RECOMMENDED\s0!\fR http://lists.sourceforge.net/lists/listinfo/nettelnetcisco\-announce .PP \&\fInettelnetcisco-users\fR is for usage discussion, help, tips, tricks, etc. http://lists.sourceforge.net/lists/listinfo/nettelnetcisco\-users .PP \&\fInettelnetcisco-devel\fR is for uber-hackers; you know who you are. http://lists.sourceforge.net/lists/listinfo/nettelnetcisco\-devel .SS "Help/discussion forums" .IX Subsection "Help/discussion forums" http://sourceforge.net/forum/?group_id=48856 .SS "Bug tracker" .IX Subsection "Bug tracker" http://sourceforge.net/tracker/?group_id=48856 .SH "SEE ALSO" .IX Header "SEE ALSO" Net::Telnet .PP Net::SNMP .PP \&\s-1UCD\s0 NetSNMP \- http://www.netsnmp.org/ .PP \&\s-1RAT/NCAT\s0 \- http://ncat.sourceforge.net/ .SH "AUTHOR" .IX Header "AUTHOR" Joshua_Keroes@eli.net \f(CW$Date:\fR 2002/12/31 00:12:32 $ .PP It would greatly amuse the author if you would send email to him and tell him how you are using Net::Telnet::Cisco. .PP As of Mar 2002, over 200 people have emailed me or posted to the Net::Telnet::Cisco site. N::T::C is used to help manage over 14,000 machines! Keep the email rolling in! .SH "THANKS" .IX Header "THANKS" The following people understand what Open Source Software is all about. Thanks Brian Landers, Aaron Racine, Niels van Dijke, Tony Mueller, Frank Eickholt, Al Sorrell, Jebi Punnoose, Christian Alfsen, Niels van Dijke, Kevin der Kinderen, Ian Batterbee, Leonardo Cont, Steve Meier, Andre Bonhote, Rob Patrick, FtR, James \*(L"mcaizjb3\*(R" Brown, and Hiro \*(L"Paul\*(R" Protagonist. .PP Paul gets a ++ for code-ninja skills. .PP Institutions: infobot.org #perl, perlmonks.org, sourceforge.net, the geeks at geekhouse.org, and eli.net. .PP Send in a patch and we can make the world a better place. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (c) 2000\-2002 Joshua Keroes, Electric Lightwave Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.