DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Perl - Cisco VLAN Removal

05.23.2007
| 6185 views |
  • submit to reddit
        // Perl - Cisco VLAN Removal
// new.txt format 
// ipaddress|loginpass|enablepass|gigabitEthernet3/48|20

#!c:/perl/bin/perl.exe

use Net::Telnet::Cisco;

open(CISCO,'new.txt');
 while (<CISCO>) {
 chomp;
my @fields = split(/\|/, $_);

my $host = $fields[0];
my $login = $fields[1];
my $telnet = $fields[2];
my $interface = $fields[3];
my $vlan = $fields[4];

#print "Content-type:text/html\n\n";
#print "Switch = <b>$host</b>    <br>";
#print "Command =  <b>username $macaddr password $macaddr</b>  <br>";

$session = Net::Telnet::Cisco->new(Host => "$host", Input_log => "input.log");
$session->login(Password => "$login");
$session->enable("$telnet");
$session->cmd("config t");
$session->cmd("int $interface");
$session->cmd("no switchport access vlan $vlan");
$session->cmd("no switchport mode access");
$session->cmd("exit");
$session->close();
}