#!/usr/bin/perl require Net::Cisco; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; my $routerip; # router ip address my $routerun; #logon username my $routerlgnpwd; #logon password my $routerenpwd; #enable password $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # open Excel file my $Book = $Excel->Workbooks->Open("c:/SCRIPTS/data.xlsx"); # select worksheet number 1 (you can also select a worksheet by name) my $Sheet = $Book->Worksheets(1); #Read the excel spread sheet for logon details foreach my $row (1..2){ #ROWS This is for a spread sheet with 2 rows and 4 columns foreach my $col (1..4){ #read row column by column use Switch; switch ($col) { #set values for telnet logon for excel row case 1 {$routerip =$Sheet->Cells($row,$col)->{'Value'}} case 2 {$routerun =$Sheet->Cells($row,$col)->{'Value'}} case 3 {$routerlgnpwd =$Sheet->Cells($row,$col)->{'Value'}} case 4 {$routerenpwd = $Sheet->Cells($row,$col)->{'Value'}} }#//switch # skip empty cells next unless defined $Sheet->Cells($row,$col)->{'Value'}; # print out the contents of a cell # printf "%s ", $Sheet->Cells($row,$col)->{'Value'}, $Sheet->Cells($row,$col)->{'Formula'}; }#// For Column print ("\nAbout to telnet to Router:\nIP: $routerip using:\nUN: $routerun \nPW: $routerenpwd \nEN: $routerlgnpwd \n"); # Log on to Router and perform commands output label the router ip. my $session = Net::Telnet::Cisco->new(Host => $routerip , Input_log =>"c:/SCRIPTS/$routerip.log"); $session->login($routerun, $routerpwd); if ($session->enable($en)){ #'cpx270zby9' @output = $session->cmd('show run | include username'); print ("Finished $routerip Router Command \n"); } else { warn `Can’t enable:`. $session -> errmsg; } $session -> close; }#//For Row $Book->Close; # close excel doc