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.17'; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
1714649
|
use 5.010; |
|
8
|
|
|
|
|
29
|
|
7
|
8
|
|
|
8
|
|
48
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
185
|
|
8
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
247
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
40
|
use Carp (); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
99
|
|
11
|
8
|
|
|
8
|
|
3037
|
use Data::Dumper (); |
|
8
|
|
|
|
|
36179
|
|
|
8
|
|
|
|
|
165
|
|
12
|
8
|
|
|
8
|
|
48
|
use Digest::MD5 (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
118
|
|
13
|
8
|
|
|
8
|
|
1652
|
use IO::Socket::INET (); |
|
8
|
|
|
|
|
65781
|
|
|
8
|
|
|
|
|
134
|
|
14
|
8
|
|
|
8
|
|
3539
|
use LWPx::ParanoidAgent (); |
|
8
|
|
|
|
|
564743
|
|
|
8
|
|
|
|
|
481
|
|
15
|
8
|
|
|
8
|
|
5436
|
use Net::Ping (); |
|
8
|
|
|
|
|
91520
|
|
|
8
|
|
|
|
|
215
|
|
16
|
8
|
|
|
8
|
|
115
|
use Time::HiRes (); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
129
|
|
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
8
|
|
3979
|
use Net::Prober::Probe::Base (); |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
3391
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub port_name_to_num { |
22
|
21
|
|
|
21
|
1
|
561
|
my ($port) = @_; |
23
|
|
|
|
|
|
|
|
24
|
21
|
100
|
66
|
|
|
176
|
if (defined $port and $port ne "" and $port =~ m{^\D}) { |
|
|
|
100
|
|
|
|
|
25
|
6
|
|
|
|
|
316
|
$port = (getservbyname($port, "tcp"))[2]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
21
|
|
|
|
|
82
|
return $port; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub probe_any { |
32
|
7
|
|
|
7
|
0
|
23
|
my ($class, $args) = @_; |
33
|
7
|
|
|
|
|
46
|
my $full_pkg = $class; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Open up for != Net::Prober::* classes |
36
|
7
|
50
|
|
|
|
32
|
if ($full_pkg !~ m{::}) { |
37
|
7
|
|
|
|
|
24
|
$full_pkg = "Net::Prober::${full_pkg}"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
7
|
50
|
|
|
|
426
|
eval "require $full_pkg; 1" or do { |
41
|
0
|
|
|
|
|
0
|
Carp::croak("Couldn't load $full_pkg class: $@"); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
68
|
my $p = $full_pkg->new(); |
45
|
7
|
|
|
|
|
26
|
return $p->probe($args); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub probe_icmp { |
49
|
1
|
|
|
1
|
0
|
436
|
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
|
10
|
return probe_any('ssh', @_); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub probe_smtp { |
65
|
1
|
|
|
1
|
0
|
13
|
return probe_any('smtp', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub probe_http { |
69
|
2
|
|
|
2
|
0
|
1713
|
return probe_any('http', @_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub probe_tcp { |
73
|
2
|
|
|
2
|
0
|
1494
|
return probe_any('tcp', @_); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub probe { |
78
|
0
|
|
|
0
|
1
|
|
my ($probe_type) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
if (! $probe_type || ref $probe_type ne 'HASH') { |
81
|
0
|
|
|
|
|
|
Carp::croak("Invalid probe data"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $host = $probe_type->{host}; |
85
|
0
|
0
|
0
|
|
|
|
if (! defined $host or $host eq "") { |
86
|
0
|
|
|
|
|
|
Carp::croak("Can't probe undefined host"); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my %probe_args = %{ $probe_type }; |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
0
|
|
|
|
my $class = lc ($probe_args{class} || 'tcp'); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Resolve port names (http => 80) |
93
|
0
|
|
|
|
|
|
$probe_args{port} = port_name_to_num($probe_args{port}); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $result = probe_any($class, \%probe_args); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return $result; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |