line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Helper::IP; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
518
|
use v5.12.5; |
|
3
|
|
|
|
|
16
|
|
8
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
128
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
530
|
use Data::Validate::IP 'is_ipv4', 'is_ipv6'; |
|
3
|
|
|
|
|
85026
|
|
|
3
|
|
|
|
|
996
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_ip { |
15
|
3
|
|
|
3
|
0
|
6
|
my ($ip) = @_; |
16
|
|
|
|
|
|
|
|
17
|
3
|
100
|
100
|
|
|
10
|
if ( is_ipv4($ip) || is_ipv6($ip) ) { |
18
|
2
|
|
|
|
|
66
|
return 1; |
19
|
|
|
|
|
|
|
} |
20
|
1
|
|
|
|
|
31
|
return 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_server_and_port { |
24
|
8
|
|
|
8
|
0
|
9120
|
my ( $server, $default_port ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
26
|
my ( $rs, $rp ); |
27
|
|
|
|
|
|
|
|
28
|
8
|
100
|
100
|
|
|
51
|
if ( $server =~ m/:(\d+)$/ && !is_ipv6($server) ) { |
29
|
2
|
|
|
|
|
44
|
return split( /:/, $server ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
6
|
100
|
|
|
|
44
|
if ( $server =~ m/\/(\d+)$/ ) { |
33
|
3
|
|
|
|
|
20
|
return split( /\/(\d+)$/, $server ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
3
|
100
|
|
|
|
8
|
if ( is_ip($server) ) { |
37
|
2
|
100
|
|
|
|
7
|
if ( is_ipv6($server) ) { |
38
|
1
|
|
|
|
|
20
|
( $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
|
|
|
16
|
$rp ||= $default_port; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
10
|
return ( $rs, $rp ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |