line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Prober::ping; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Net::Prober::ping::VERSION = '0.15'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
3
|
use base 'Net::Prober::Probe::Base'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
257
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub defaults { |
11
|
|
|
|
|
|
|
return { |
12
|
1
|
|
|
1
|
0
|
7
|
host => undef, |
13
|
|
|
|
|
|
|
port => undef, |
14
|
|
|
|
|
|
|
timeout => undef, |
15
|
|
|
|
|
|
|
# icmp requires root privileges, but we don't use tcp |
16
|
|
|
|
|
|
|
# because it may incorrectly report hosts as down |
17
|
|
|
|
|
|
|
proto => 'icmp', |
18
|
|
|
|
|
|
|
size => undef, |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub probe { |
23
|
1
|
|
|
1
|
0
|
1
|
my ($self, $args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
8
|
my ($host, $port, $timeout, $proto, $size) = |
26
|
|
|
|
|
|
|
$self->parse_args($args, qw(host port timeout proto size)); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#my ($host, $port, $timeout, $proto, $size) = |
29
|
|
|
|
|
|
|
# @{$probe}{qw(host port timeout proto size)}; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
8
|
my $pinger = Net::Ping->new($proto, $timeout); |
32
|
1
|
|
|
|
|
242
|
$pinger->hires(); |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
8
|
if (defined $port) { |
35
|
0
|
0
|
|
|
|
0
|
if ($proto eq 'icmp') { |
36
|
0
|
|
|
|
|
0
|
Carp::croak("Ping on port $port with icmp protocol is not implemented"); |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
0
|
$pinger->port_number($port); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
3
|
my ($ok, $elapsed, $ip) = $pinger->ping($host); |
42
|
1
|
|
|
|
|
223557
|
$pinger->close(); |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
55
|
my $result = { |
45
|
|
|
|
|
|
|
ok => $ok ? 1 : 0, |
46
|
|
|
|
|
|
|
time => $elapsed, |
47
|
|
|
|
|
|
|
ip => $ip, |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
10
|
return $result; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |