My boss asked me whether if there is any possibility to check telnet accessibility for a number of routers,all the routers are CISCO so i did download cisco module and installed, as you can see at the second line of the program i used "Net:Cisco module".i kept all the ips in the "iplist.txt" and reading each ip and checking telnet accessibility and also writing output to a output.txt file which writes "telnet success" if access is possible otherwise writes "telnet failed" with respect to each ip.
#/usr/bin/perl
use Net::Cisco;
open(IPLIST,"<iplist.txt")or die "couldn't open iplist.txt";
open(OUTPUT,">output.txt");
$count=0;
while(<IPLIST>)
{
chomp($_);
$data=$_;
tel($data);
$count++;
}
close(IPLIST);
sub tel
{
$tl=0;
$t=Net::Telnet::Cisco->new(Host=>$data,Timeout=>7,Errmode=>'return')or $tl=1;
if($tl==0)
{
print "$data,telnet success\n";
print OUTPUT "$data,Telnet success\n";
$t->close;
}
else
{
print "$data,Telnet Failed\n";
print OUTPUT "$data,Device Telnet Failed\n";
}
}
close(OUTPUT);
#/usr/bin/perl
use Net::Cisco;
open(IPLIST,"<iplist.txt")or die "couldn't open iplist.txt";
open(OUTPUT,">output.txt");
$count=0;
while(<IPLIST>)
{
chomp($_);
$data=$_;
tel($data);
$count++;
}
close(IPLIST);
sub tel
{
$tl=0;
$t=Net::Telnet::Cisco->new(Host=>$data,Timeout=>7,Errmode=>'return')or $tl=1;
if($tl==0)
{
print "$data,telnet success\n";
print OUTPUT "$data,Telnet success\n";
$t->close;
}
else
{
print "$data,Telnet Failed\n";
print OUTPUT "$data,Device Telnet Failed\n";
}
}
close(OUTPUT);
No comments:
Post a Comment