-->
#!/usr/bin/perl
use warnings;
use strict;
use Net::Ping;
die "$0: 需要指定主机列表
" if !@ARGV ;
my $conf_file=shift;
my ($icmp,$udp,$tcp,$win32);
my @hostlist;
$win32 = $^O eq 'MSWin32';
$icmp=Net::Ping->new('icmp',3);
$udp=Net::Ping->new('udp',3);
$tcp=Net::Ping->new('tcp') if !$win32;
open FD,"$conf_file";
@hostlist=<FD>;
print "ICMP UDP TCP 主机 描述\n";
foreach my $i (@hostlist){
chomp $i;
my ($host,$comment)=split /\s+/,$i;
printf "%-8s",$icmp->ping($host) || 'undef';
printf "%-8s",$udp->ping($host) || 'undef';
printf "%-8s",$win32 ? '不可用' :($tcp->ping($host) || 'undef');
print "$host\t";
print "$comment\n";
}
$icmp->close;
$udp->close;
$tcp->close if !$win32;
主机列表文件格式:
127.0.0.1 本机
xxx.xxx.xxx.xxx 网关
xxx.xxx.xxx.xxx ISP接口
[root@supersun network]# ./netping.pl file
ICMP UDP TCP 主机 描述
1 1 1 127.0.0.1 本机
1 undef 1 xxx.xxx.xxx.xxx 网关
1 undef 1 xxx.xxx.xxx.xxx ISP接口

发表评论