line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ABSTRACT: IPv4/IPv6 addresses validator |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::IP::Checker; |
5
|
|
|
|
|
|
|
$Net::IP::Checker::VERSION = '0.03'; |
6
|
1
|
|
|
1
|
|
48506
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
340
|
use Regexp::IPv6 qw($IPv6_re); |
|
1
|
|
|
|
|
626
|
|
|
1
|
|
|
|
|
103
|
|
9
|
1
|
|
|
1
|
|
302
|
use Regexp::IPv4 qw($IPv4_re); |
|
1
|
|
|
|
|
149
|
|
|
1
|
|
|
|
|
215
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(ip_get_version ip_is_ipv4 ip_is_ipv6); |
15
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'ALL' => [@EXPORT_OK] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub ip_get_version { |
19
|
2
|
|
|
2
|
1
|
4
|
my $ip = shift; |
20
|
2
|
100
|
66
|
|
|
11
|
$ip !~ /:/ and ip_is_ipv4($ip) and return '4'; |
21
|
1
|
50
|
|
|
|
3
|
ip_is_ipv6($ip) and return '6'; |
22
|
0
|
|
|
|
|
0
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ip_is_ipv4 { |
27
|
16
|
|
|
16
|
1
|
2722
|
my $ip = shift; |
28
|
16
|
100
|
|
|
|
160
|
return $ip =~ /^$IPv4_re$/ ? 1 : 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub ip_is_ipv6 { |
33
|
24
|
|
|
24
|
1
|
3875
|
my $ip = shift; |
34
|
24
|
100
|
|
|
|
600
|
return $ip =~ /^$IPv6_re$/ ? 1 : 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |