| 1 | # ABSTRACT: Probes network hosts for downtime, latency, etc... | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Net::Prober; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | $Net::Prober::VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Digest::MD5 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use IO::Socket::INET (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use LWPx::ParanoidAgent (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Net::Ping (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use Net::Prober::Probe::Base (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | sub port_name_to_num { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 21 | ▶ | my ($port) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
port_name_to_num: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 21 | ▶ | if (defined $port and $port ne "" and $port =~ m{^\D}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $port and $port ne "" and $port =~ /^\D/
defined $port and $port ne ""
MC/DC66%2/3
defined $port and $port ne "" and $port =~ /^\D/
defined $port
$port ne ""
$port =~ /^\D/
Truth table75%3/4
A and B and C
A= defined $portB= $port ne ""C= $port =~ /^\D/
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | $port = (getservbyname($port, "tcp"))[2]; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 21 | return $port; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub probe_any { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | my ($class, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_any: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | my $full_pkg = $class; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Open up for != Net::Prober::* classes | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | if ($full_pkg !~ m{::}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | $full_pkg = "Net::Prober::${full_pkg}"; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | ▶ | eval "require $full_pkg; 1" or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | Carp::croak("Couldn't load $full_pkg class: $@"); | |||||||||||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | my $p = $full_pkg->new(); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | return $p->probe($args); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub probe_icmp { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return probe_any('ping', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_icmp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub probe_ping { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return probe_any('ping', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_ping: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | sub probe_imap { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return probe_any('imap', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_imap: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | sub probe_ssh { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | return probe_any('ssh', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_ssh: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | sub probe_smtp { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return probe_any('smtp', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_smtp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub probe_http { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | return probe_any('http', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_http: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | sub probe_tcp { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | return probe_any('tcp', @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_tcp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub probe { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | my ($probe_type) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe: called CC=6 SCAR=20.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if (! $probe_type || ref $probe_type ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $probe_type or ref $probe_type ne "HASH"
MC/DC0%0/2
not $probe_type or ref $probe_type ne "HASH"
not $probe_type
ref $probe_type ne "HASH"
Truth table33%1/3
not(A) or B
A= not $probe_typeB= ref $probe_type ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | Carp::croak("Invalid probe data"); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my $host = $probe_type->{host}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | if (! defined $host or $host eq "") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $host or $host eq ""
MC/DC0%0/2
not defined $host or $host eq ""
not defined $host
$host eq ""
Truth table33%1/3
not(A) or B
A= not defined $hostB= $host eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | Carp::croak("Can't probe undefined host"); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | my %probe_args = %{ $probe_type }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | my $class = lc ($probe_args{class} || 'tcp'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$probe_args{'class'} || 'tcp'
MC/DC0%0/1
$probe_args{'class'} || 'tcp'
$probe_args{'class'}
Truth table50%1/2
A
A= $probe_args{'class'}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Resolve port names (http => 80) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $probe_args{port} = port_name_to_num($probe_args{port}); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $result = probe_any($class, \%probe_args); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||||||||||||||||