Skip to main content

Perl Scripts to manipulate Cisco gear

More
16 years 9 months ago #22208 by Smurf

Anyone looking for a scripting environment which is tightly integrated into Windows, .NET, Active Directory should definitely give Windows PowerShell a look. I have been playing with it for a couple of months and it is unbelievable. The only downside is that you can only use it on Windows XP, Vista and 2003.


I know this is going off topic a little but the new Windows PowerShell is where Microsoft seem to be shifting all their scripting functionality to. Its used to configure a lot of Microsoft tasks within the scripting engine. A lot of the new Exchange 2007 tasks are not available through the GUI's and you HAVE to use PowerShell to perform them functions.

I will not be supprised if a lot more moves in this direction.

Wayne Murphy
Firewall.cx Team Member
www.firewall.cx

Now working for a Security Company called Sec-1 Ltd in the UK, for any
Penetration Testing work visit www.sec-1.com or PM me for details.
More
16 years 9 months ago #22214 by DaLight
First of all, Powershell is only relevant in a Windows context, whereas Perl can be used on a cross-platform basis. If this is the case, however (Windows environment) Powershell can be incredibly powerful as it gives you direct access to objects in the .NET framework. One-line commands can be used in place of page long scripts and it gives system administrators access to the methods and properties of system objects right from the command-line. And all one needs to download is the actual Powershell installer. And since most machines (XP and above) already have the .NET framework installed, you're ready to go!
More
16 years 9 months ago #22215 by MatthewUHS
Hey Chris,

Thanks for the pointer to Expect. Did you use Auto-expect to record your interaction with your cisco gear and thereby auto-generate your script? I bounced to the site after reading your post and came across Auto-expect in the script samples.

This IS an interesting post I hope more folks weigh in as this promotes the true sense of what this site was inteded to be.

(Was that over the top?...lol)

Matt

Wires and fires has become wireless and tireless.
More
14 years 7 months ago #31276 by Perlhack
Below is a basic script to deploy commands to routers that have IP addresses populated in the @IP array. Plug in username, password, and enable password. In the command section put in the CLI syntax. Launch script and watch the automation.


#!/usr/bin/perl
use Net::Telnet::Cisco;
system(clear);
print "\n\n
Deploy configuration to router
\n\n";
@IP = qw(192.168.1.1 192.168.2.1 192.168.3.1 192.168.4.1 192.168.7.1 192.168.8.1);

foreach $IP (@IP) {
print "Connecting to $IP\n";
$prmpt = '/#/';
$session = Net::Telnet::Cisco->new(Host => "$IP",Prompt=>'/#$/',Errmode=>'return');
$session->input_log(*STDOUT);
$session->waitfor_pause(1);
$session->login('username', 'password');
$session->enable('enable_password');
@output = $session->cmd("
conf t
int eth 0/0
ip igmp join-group 225.1.1.1
do wr
");
$session->cmd("");
$session->cmd("");

push (@IPP, $IP);
print "\n\n";
sleep 1;
$session->close;
}
print "
Script completed to
\n\n";
foreach (@IPP) {
print "$_\n";
}
More
14 years 7 months ago #31295 by TheBishop
Nice script!
I must read up on that Net::Telnet::Cisco module; didn't know there was a specific Cisco one
More
13 years 6 months ago #35494 by MatthewUHS
Thanks guys, funny thing is, I just got on today to ask the same question. I finally got some time to look into it again.

Wires and fires has become wireless and tireless.
Time to create page: 0.153 seconds