line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Prober::ping; |
2
|
|
|
|
|
|
|
$Net::Prober::ping::VERSION = '0.17'; |
3
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
7
|
use base 'Net::Prober::Probe::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
215
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub defaults { |
8
|
|
|
|
|
|
|
return { |
9
|
1
|
|
|
1
|
0
|
4
|
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
|
2
|
my ($self, $args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
6
|
my $pinger = Net::Ping->new($proto, $timeout); |
29
|
1
|
|
|
|
|
202
|
$pinger->hires(); |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
9
|
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
|
|
|
|
|
699
|
$pinger->close(); |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
28
|
my $result = { |
42
|
|
|
|
|
|
|
ok => $ok ? 1 : 0, |
43
|
|
|
|
|
|
|
time => $elapsed, |
44
|
|
|
|
|
|
|
ip => $ip, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
6
|
return $result; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |