首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 电脑技能 >

用Perl访问华为交换机配备示例

2013-02-18 
用Perl访问华为交换机配置示例#!/usr/bin/perl -wuse lib ../hwlibuse Net::Telnetuse Time::Localus

用Perl访问华为交换机配置示例

#!/usr/bin/perl -wuse lib '../hwlib';use Net::Telnet;use Time::Local;use POSIX qw(strftime);use HWNET;use Net::Ping;my $p = Net::Ping->new();my $host='10.49.64.1';if(!$p->ping($host)){    print STDERR "Can NOT ping '$host' !";    goto r2;}my $hw = new HWNET;$hw->login($host, 'admin', 'pass1', 'pass2');$hw->super();# 取得交换机时间my @sw_clock = $hw->exec_cmd('disp clock');goto r1 if @sw_clock == 0;# $4年$5月$6日 $1时$2分$3秒;my $re_time = '(\d{2}):(\d{2}):(\d{2}) UTC [a-zA-Z]{3} (\d{4})/(\d{2})/(\d{2})';$sw_clock[0] =~ /$re_time/;my $time = timelocal($3,$2,$1,$6,$5-1,$4);#my $s =localtime($time);#print 'ok' if time < $time;# 取得最近12条logbuffer 记录my @log = $hw->exec_cmd('disp logb size 10');my %arp_hash=();#%Jan 29 11:42:01 2007my $re = '^%[a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} .+? sourced by ([0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}) on';for(@log){    next if !($_ =~ /$re/i);    $arp_hash{$1} = 1 if !exists($arp_hash{$1});    $arp_hash{$1} = $arp_hash{$1} + 1;}for(keys %arp_hash){    print STDERR "有毒的机器MAC地址为:$_", "\n" if($arp_hash{$_} > 1);}print STDERR '没有发现中毒的MAC机器地址!', "\n" if keys %arp_hash == 0;r1:$hw->logout;r2:$p->close();

热点排行