Home > PerlScripts > Telnet script for switches

Telnet script for switches

September 5th, 2008 Leave a comment Go to comments

Can you imagine telneting into 700+ switches to update just a single line? Well with this script it can be done in a very easy way, it does require Perl and the Net::Telnet::Cisco library.
In this case I used the script to update Alcatel Switches OminiStack but it should also work for Cisco Switches/Routers.

Download here, or copy and paste to file.pl and run perl file.pl hosts.txt

#!/usr/local/bin/perl -w
# Remote exec commands into a list of switches (Alcatel, OminiStack, Cisco) by telenet
# Author: Felipe Ferreira
# Date 05/09/2008
# Version: 0.3
# tip: open the .logs in gedit, because cat won't display all chars.
use Net::Telnet::Cisco ();

my $username = "admin";
my $passwd = "passnow";

if (!defined($ARGV[0]))
print "n Usage :$0 n";
print "Example: $0 hosts.txtn";
print "n Author: Felipe Ferreira nn";
exit 1;
$filehosts = $ARGV[0];

#Get all hosts IPs from the text file and pass to an array
open(DATA, $filehosts);
@swtichlist= ;
foreach (@swtichlist) {
$host=shift @swtichlist;
$host =~s/t+//;
chomp ($host);

print "Loging to: $host n";

sub TELNET {
$t = Net::Telnet::Cisco -> new (
Timeout => 5,
Binmode => "true",
Prompt => '/#/',
Dump_log => "dump.log",
Input_log => "$host.log");

#Start Connecting
$t->send_wakeup( 'connect' );
$t->cmd('snmp-server community caca rw view DefaultSuper');
$t->send_wakeup( 'connect' );
$t->cmd("copy running-config startup-config");
print "Done, check .log n";

# ref:
# http://www.ruby-doc.org/stdlib/libdoc/net/telnet/rdoc/classes/Net/Telnet.html
# http://nettelnetcisco.sourceforge.net/docs.html#name

  1. Chris Carson
    August 25th, 2009 at 03:35 | #1

    I cannot get the script to execute. I receive an error.

    perl file.pl hosts.txt
    syntax error at file.pl line 24, near “= ;”
    Execution of file.pl aborted due to compilation errors.

    hosts.txt is a file that includes a list of IP addresses.

    Thanks for any assistance you might have.

  2. alpha
    August 12th, 2014 at 14:45 | #2

    the community caca is the best

  1. No trackbacks yet.