Perl Telnet 登錄 Cisco交換機,並執行命令。

#! /usr/bin/perl -w
use strict;
use 5.010;

use Net::Telnet::Cisco;  

#需要安裝這個module, 需要有internet連接, windows安裝命令如下

#c:\> cpan

#cpan> install Net::Telnet::Cisco;  


# hostip1 數組中可放入多個交換機地址,在循環中執行命令。

my @hostip1 = qw(
22.10.100.11
);

foreach my $ip (@hostip1) {
        my $conn = Net::Telnet::Cisco->new(Host => $ip);
        my $vtyPass = 'xxxxxxxx'';
        my $enaPass = 'xxxxxxxx';
        $conn->login(Password => $vtyPass);
       $conn->enable($enaPass);

       my  $cmd = 'show run';
       @output = $conn->cmd($cmd);
       print "Output: @output"; 

       $conn->close;

}

# 參考網址 http://www.litvip.com/2011/08/29/554


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章