Never been to DZone Snippets before?

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

About this user

Amanda Emily

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Perl - Cisco VLAN Removal

// 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();
}

Perl - Cisco Wireless Managment

// Perl script to update MAC access table on Cisco IOS-based AiroNets

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

# Update Aironet IOS mac addresses

use Net::Telnet::Cisco;
use vars qw($r @data);

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}


$macaddr = $FORM{'command'};
#$macaddr = 'AABBCCDDEEFF';

print "using command <u>username <b>$macaddr</b> password <b>0$macaddr</b></u><br><br>";

	
print "Updating AP <b>127.0.0.1 (conference center)</b>    <br>";
$r = Net::Telnet::Cisco->new(Host=>"127.0.0.1");
	$r->login("login","password");
die($r->errmsg) unless($r->enable("password"));
	$r->cmd('terminal length 0');
	$r->cmd('config t');
	$r->cmd("username $macaddr password $macaddr");
	$r->cmd("username $macaddr autocommand exit");
	$r->cmd("exit");
	$r->cmd("write memory quiet");
	$r->cmd('terminal length 24');
	$r->close();
print "Done!";
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS