Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Script to set arp on Cisco, what is wrong?

Status
Not open for further replies.

baboom2

Technical User
Feb 5, 2009
1
RO
Hello,

I try to make a script. It reads variables from a list (/root/test/list). I have 6 columns but i need only 3: IP, MAC and STATUS column. I need to read from "list" wich IP have status ON and those who are ON to set fixed arp through telnet on my Cisco router.

Here is my script:
proc.pl
#!/usr/bin/perl

my $cisco_host = "xx.xx.xx.xx";
my $cisco_user = "xxx";
my $cisco_pass = "xxx";

use strict;

open(INPUT,"/root/test/list") or die("File not found!\n");
my @input = <INPUT>;
close(INPUT);

my $line;
my $ip;
my $mac;
my %clients;
for $line (@input) {
my ($name,$ip,$mac,$cir,$mir,$status) = split(/\s+/,$line);
print "Processing $name\n";
print "Found $ip , $mac with status $status\n";
$clients{$ip}{status} = $status;
}

require 'csmod.pl';
my $telnet = cisco_Connect($cisco_host,$cisco_user,$cisco_pass) ;

foreach $ip (keys %clients)
{
if($clients{$ip}{status} eq "on") {
$telnet->cmd("arp $ip $mac ARPA");
}
}


#$telnet->cmd("do wr");
$telnet->cmd("exit");
$telnet->cmd("exit");


and here is csmod.pl

use strict;
use Net::Telnet::Cisco;

sub cisco_Connect {
my ($cisco_host,$cisco_user,$cisco_pass,$enable_pass) = @_;
my $telnet = new Net::Telnet::Cisco(Timeout => 10);
$telnet->open($cisco_host);
$telnet->login($cisco_user,$cisco_pass);
$telnet->enable("xxx");
return($telnet);
}

1;

Here is "list" format:

Name 192.168.x.x 00:11:22:33:44:55 2 64 on

When i run the script it gives me the following error:
Use of uninitialized value in concatenation (.) or string at proc.pl line 41.
Line 41 is: $telnet->cmd("arp $ip $mac ARPA");

What i do wrong?
Thank you in advance for your help!
 
my $telnet = cisco_Connect($cisco_host,$cisco_user,$cisco_pass) ;

to

my $telnet = cisco_Connect($cisco_host,$cisco_user,$cisco_pass) or die "Can't connect: $!\n";

see if that tells you anything.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
baboom2,

I thought I got this one working for you on another forum.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top