line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Detect; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27610
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Net::Detect::VERSION = '0.3'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1305
|
use Net::Ping 2.41 (); |
|
1
|
|
|
|
|
57387
|
|
|
1
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; ## no critic |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
192
|
|
12
|
2
|
|
|
2
|
|
21
|
*{ caller() . '::detect_net' } = \&detect_net; |
|
2
|
|
|
|
|
24
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub detect_net { |
16
|
0
|
|
|
0
|
1
|
|
my ( $host, $port, @new ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
0
|
|
|
|
$host ||= 'www.google.com'; |
19
|
0
|
|
0
|
|
|
|
$port ||= 80; |
20
|
0
|
0
|
|
|
|
|
$port = 80 if !abs( int($port) ); |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
my $np = Net::Ping->new( @new ? @new : 'syn' ); |
23
|
0
|
|
|
|
|
|
$np->port_number($port); |
24
|
0
|
|
|
|
|
|
my $has_net = $np->ping($host); |
25
|
0
|
|
|
|
|
|
$np->close(); |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
return 1 if $has_net; |
28
|
0
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |