#!c:/perl/bin/perl use strict; use warnings; use Net::Telnet::Cisco; use DBI; use DBD::mysql; use Env; use File::Path; use File::Basename; use IO::Handle; use Config::IniFiles; use Term::ReadKey; ######################################################################################################## # Global Variables ##################################################################################### ######################################################################################################## my $username = "admin"; my $password = "admin"; my $host = "172.16.0.2"; my @output; my $input_log; my $output_log; my $directory = "c:/perl/bin/test/"; #Check for the presence of the log file directory. If not there, create it eval { mkpath($directory); if ($@) { print "Couldn't create path: $@"; } else { mkpath($directory); } }; ######################################################################################################## # Global Variables ##################################################################################### ######################################################################################################## ######################################################################################################## # Controller Connection ################################################################################ ######################################################################################################## system "cls"; print "Connecting to controller ...\n"; my $session = Net::Telnet::Cisco->new( Host => $host, Prompt => '/\(Cisco Controller\)/', Errmode => 'return', Timeout => 5); $session->open($host); # Wait for the username prompt and enter username $session->waitfor('/^User:.*$/'); $session->print($username); # Wait for the password prompt and enter password $session->waitfor('/^Password:.*$/'); $session->print($password); $session->cmd("config paging disable"); ######################################################################################################## # Controller Connection ################################################################################ ######################################################################################################## get_ap_summary(); show_run(); show_inventory(); cleanup(); exit(); ######################################################################################################## # Subroutines ########################################################################################## ######################################################################################################## sub get_ap_summary { print "\nGetting AP Summary ...\n"; #my @output; $input_log = $directory . $host . "_get_ap_summary_in.log"; $output_log = $directory . $host . "_get_ap_summary_out.log"; $session->input_log($output_log); $session->output_log($input_log); @output = $session->cmd("show ap summary"); return; } sub show_run { print "\nGetting Running Config ...\n"; #my @output; $input_log = $directory . $host . "_get_run_config_in.log"; $output_log = $directory . $host . "_get_run_config_out.log"; $session->input_log($output_log); $session->output_log($input_log); @output = $session->cmd("show run-config"); return; } sub show_inventory { print "\nGetting inventory ...\n"; #my @output; $input_log = $directory . $host . "_get_inventory_in.log"; $output_log = $directory . $host . "_get_inventory_out.log"; $session->input_log($output_log); $session->output_log($input_log); @output = $session->cmd("show inventory"); return; } sub cleanup { print "\nClosing telnet connection ...\n"; $session->cmd("config paging enable"); $session->close; print "FINISHED\n"; } ######################################################################################################## # Subroutines ########################################################################################## ########################################################################################################