Net::Ping的简单使用

| 暂无评论 | 暂无引用通告

-->

#!/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接口
 

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/618
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年4月24日 09:46

此Blog上的上一篇日记使用-d选项进行perl脚本试调

此Blog上的下一篇日记红烧肉的做法

首页归档页可以看到最新的日记和所有日记。