perl实现ping包的一个例子,包括TCP、UDP数据包的ping。
代码:
#!/usr/bin/perl
use warnings;
use Net::Ping;
$hostname = shift @ARGV;
$p = Net::Ping->new("icmp"); #could be "udp" or "tcp" instead
print "$host is alive.n" if $p->ping($host);
$p->close();
Ping a host
#!/bin/perl
use Net::Ping;
$pingobject = Net::Ping->new(icmp);
if ($pingobject->ping('cpan.org')) {print "Could reach CPAN."};
$pingobject->close();