line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Probes network hosts for downtime, latency, etc... |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::Prober; |
4
|
|
|
|
|
|
|
$Net::Prober::VERSION = '0.16'; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
1274569
|
use 5.010; |
|
8
|
|
|
|
|
22
|
|
7
|
8
|
|
|
8
|
|
26
|
use strict; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
149
|
|
8
|
8
|
|
|
8
|
|
38
|
use warnings; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
197
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
24
|
use Carp (); |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
91
|
|
11
|
8
|
|
|
8
|
|
3237
|
use Data::Dumper (); |
|
8
|
|
|
|
|
34977
|
|
|
8
|
|
|
|
|
147
|
|
12
|
8
|
|
|
8
|
|
45
|
use Digest::MD5 (); |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
93
|
|
13
|
8
|
|
|
8
|
|
1818
|
use IO::Socket::INET (); |
|
8
|
|
|
|
|
65470
|
|
|
8
|
|
|
|
|
134
|
|
14
|
8
|
|
|
8
|
|
3853
|
use LWPx::ParanoidAgent (); |
|
8
|
|
|
|
|
548857
|
|
|
8
|
|
|
|
|
364
|
|
15
|
8
|
|
|
8
|
|
5012
|
use Net::Ping (); |
|
8
|
|
|
|
|
65812
|
|
|
8
|
|
|
|
|
181
|
|
16
|
8
|
|
|
8
|
|
142
|
use Time::HiRes (); |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
113
|
|
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
8
|
|
3646
|
use Net::Prober::Probe::Base (); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
2884
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub port_name_to_num { |
22
|
22
|
|
|
22
|
1
|
258
|
my ($port) = @_; |
23
|
|
|
|
|
|
|
|
24
|
22
|
100
|
66
|
|
|
155
|
if (defined $port and $port ne "" and $port =~ m{^\D}) { |
|
|
|
100
|
|
|
|
|
25
|
6
|
|
|
|
|
386
|
$port = (getservbyname($port, "tcp"))[2]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
82
|
return $port; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub probe_any { |
32
|
8
|
|
|
8
|
0
|
16
|
my ($class, $args) = @_; |
33
|
8
|
|
|
|
|
102
|
my $full_pkg = $class; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Open up for != Net::Prober::* classes |
36
|
8
|
50
|
|
|
|
28
|
if ($full_pkg !~ m{::}) { |
37
|
8
|
|
|
|
|
31
|
$full_pkg = "Net::Prober::${full_pkg}"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
8
|
50
|
|
|
|
718
|
eval "require $full_pkg; 1" or do { |
41
|
0
|
|
|
|
|
0
|
Carp::croak("Couldn't load $full_pkg class: $@"); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
67
|
my $p = $full_pkg->new(); |
45
|
8
|
|
|
|
|
23
|
return $p->probe($args); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub probe_icmp { |
49
|
1
|
|
|
1
|
0
|
157
|
return probe_any('ping', @_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub probe_ping { |
53
|
0
|
|
|
0
|
0
|
0
|
return probe_any('ping', @_); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub probe_imap { |
57
|
0
|
|
|
0
|
0
|
0
|
return probe_any('imap', @_); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub probe_ssh { |
61
|
1
|
|
|
1
|
0
|
14
|
return probe_any('ssh', @_); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub probe_smtp { |
65
|
1
|
|
|
1
|
0
|
11
|
return probe_any('smtp', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub probe_http { |
69
|
2
|
|
|
2
|
0
|
313
|
return probe_any('http', @_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub probe_tcp { |
73
|
2
|
|
|
2
|
0
|
1233
|
return probe_any('tcp', @_); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub probe { |
78
|
1
|
|
|
1
|
1
|
639
|
my ($probe_type) = @_; |
79
|
|
|
|
|
|
|
|
80
|
1
|
50
|
33
|
|
|
10
|
if (! $probe_type || ref $probe_type ne 'HASH') { |
81
|
0
|
|
|
|
|
0
|
Carp::croak("Invalid probe data"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
2
|
my $host = $probe_type->{host}; |
85
|
1
|
50
|
33
|
|
|
10
|
if (! defined $host or $host eq "") { |
86
|
0
|
|
|
|
|
0
|
Carp::croak("Can't probe undefined host"); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
2
|
my %probe_args = %{ $probe_type }; |
|
1
|
|
|
|
|
5
|
|
90
|
1
|
|
50
|
|
|
4
|
my $class = lc ($probe_args{class} || 'tcp'); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Resolve port names (http => 80) |
93
|
1
|
|
|
|
|
4
|
$probe_args{port} = port_name_to_num($probe_args{port}); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
3
|
my $result = probe_any($class, \%probe_args); |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
6
|
return $result; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |