line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Helper::IP; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
558
|
use v5.12.5; |
|
3
|
|
|
|
|
16
|
|
8
|
3
|
|
|
3
|
|
28
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
129
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
542
|
use Data::Validate::IP 'is_ipv4', 'is_ipv6'; |
|
3
|
|
|
|
|
87828
|
|
|
3
|
|
|
|
|
1023
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_ip { |
15
|
3
|
|
|
3
|
0
|
6
|
my ($ip) = @_; |
16
|
|
|
|
|
|
|
|
17
|
3
|
100
|
100
|
|
|
12
|
if ( is_ipv4($ip) || is_ipv6($ip) ) { |
18
|
2
|
|
|
|
|
65
|
return 1; |
19
|
|
|
|
|
|
|
} |
20
|
1
|
|
|
|
|
31
|
return 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_server_and_port { |
24
|
8
|
|
|
8
|
0
|
9158
|
my ( $server, $default_port ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
14
|
my ( $rs, $rp ); |
27
|
|
|
|
|
|
|
|
28
|
8
|
100
|
100
|
|
|
50
|
if ( $server =~ m/:(\d+)$/ && !is_ipv6($server) ) { |
29
|
2
|
|
|
|
|
43
|
return split( /:/, $server ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
6
|
100
|
|
|
|
47
|
if ( $server =~ m/\/(\d+)$/ ) { |
33
|
3
|
|
|
|
|
22
|
return split( /\/(\d+)$/, $server ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
3
|
100
|
|
|
|
8
|
if ( is_ip($server) ) { |
37
|
2
|
100
|
|
|
|
7
|
if ( is_ipv6($server) ) { |
38
|
1
|
|
|
|
|
19
|
( $rs, $rp ) = split( /\//, $server ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
1
|
|
|
|
|
22
|
( $rs, $rp ) = split( /[:\/]/, $server ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
1
|
|
|
|
|
6
|
( $rs, $rp ) = split( /[:\/]/, $server ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
33
|
|
|
15
|
$rp ||= $default_port; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
9
|
return ( $rs, $rp ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |