#!/usr/bin/perl use Net::Telnet; use strict; #********************** User defined variables ************************************* my $username='adminuser'; my $password='xxxxxxxxx'; my $machine='192.168.102.21'; #*********************************************************************************** #Open telnet session to host my $telnet = new Net::Telnet ( Timeout=>30, Errmode=>'die', Input_log => 'logs\\telnet-remove-exclusions-log-WLC02.txt'); $telnet->open($machine); $telnet->waitfor('/User: $/i'); $telnet->print($username); $telnet->waitfor('/Password:$/i'); $telnet->print($password); $telnet->waitfor('/\(Cisco Controller\) >$/i'); #check for error status which should be undefined my $msg = $telnet->errmsg; print "$msg\n"; #loop while the command does not timeout looking for a different prompt while (not $msg) { my @output = $telnet->cmd(String => 'show exclusionlist', Prompt => '/Would you like to display the next 15 entries?/', errmode => 'return'); $msg = $telnet->errmsg; $telnet->print('N'); print @output; foreach my $mac (@output) { if ($mac =~ m/([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})/) { my $cmd = "config exclusionlist delete " . $mac; $telnet->cmd(String => $cmd, Prompt => '/\(Cisco Controller\) >$/i'); } } } #once command times out looking for the continue prompt, run it one more time with the regular prompt my @output = $telnet->cmd(String => 'show exclusionlist', Prompt => '/\(Cisco Controller\) >$/i', errmode => 'return'); print @output; foreach my $mac (@output) { if ($mac =~ m/([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})\:([a-fA-F0-9]{2})/) { my $cmd = "config exclusionlist delete " . $mac; $telnet->cmd(String => $cmd, Prompt => '/\(Cisco Controller\) >$/i'); } } $telnet->print('logout');