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.01'; |
6
|
1
|
|
|
1
|
|
61064
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
467
|
use Regexp::IPv6 qw($IPv6_re); |
|
1
|
|
|
|
|
773
|
|
|
1
|
|
|
|
|
140
|
|
9
|
1
|
|
|
1
|
|
386
|
use Regexp::IPv4 qw($IPv4_re); |
|
1
|
|
|
|
|
185
|
|
|
1
|
|
|
|
|
223
|
|
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
|
|
|
16
|
$ip !~ /:/ and ip_is_ipv4($ip) and return '4'; |
21
|
1
|
50
|
|
|
|
4
|
ip_is_ipv6($ip) and return '6'; |
22
|
0
|
|
|
|
|
0
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ip_is_ipv4 { |
27
|
16
|
|
|
16
|
1
|
3158
|
my $ip = shift; |
28
|
16
|
100
|
|
|
|
197
|
return $ip =~ /^$IPv4_re$/ ? 1 : 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub ip_is_ipv6 { |
33
|
24
|
|
|
24
|
1
|
4635
|
my $ip = shift; |
34
|
24
|
100
|
|
|
|
774
|
return $ip =~ /^$IPv6_re$/ ? 1 : 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |