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