⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expect.pl

📁 在UniX下实现了有关于使用snmp网络管理协议来管理IP绑定的问题
💻 PL
字号:
use Expect;
use strict;
use warnings;

sub readdata{
open(FILEHANDLE,"switch.txt")||die"can not open filename:$!";
my(@array)=<FILEHANDLE>;
chomp@array;
close(FILEHANDLE);
return(@array);
}

my @list=&readdata;
for(my $i=0;$i<=$#list;$i++){

	my @route=split /,/,$list[$i];
	my $timeout = 20;
	my $cmd1 = "telnet";


	my @params = "$route[0]";
	my $exp = Expect->spawn($cmd1,@params) or die "Can't spawn $cmd1!";
	$exp->expect($timeout,-re=>'Username:');
	$exp->send("$route[1]\n");	
	$exp->expect($timeout,-re=>'Password:');
	$exp->send("$route[2]\n");
	$exp->send("su\n");
	$exp->expect($timeout,-re=>'Password:');
	$exp->send("$route[3]\n");
	$exp->send("sy\n");
	$exp->send("dis arp\n");
	$exp->send(" \n");
	$exp->send(" \n");
	$exp->send(" \n");
	$exp->send(" \n");



	$exp->log_file("switch_data.txt");



	$exp->soft_close();
}


open(FIE1,"switch_data.txt") || die"can not open filename:$!";
my(@array1)=<FIE1>;
chomp@array1;


open(FIE2,">>ip.txt")||die"can not open filename:$!";
my(@array2)=<FIE2>;
chomp@array2;
for(my $h=0;$h<=$#array2;$h++){
	my @ip_to_mac=grep /$array2[$h]/,@array1;
	print FIE2 "@ip_to_mac";
}


close(FIE2);

close(FIE1);

chomp( my $file = <switch_data.txt> );
-f $file && unlink( $file );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -