Data::Checker::IP - check data to see if it is a valid IP
use Data::Checker; $obj = new Data::Checker; $obj->check($data,"IP",$check_opts);
This module is meant to be used by the Data::Checker module.
One set of checks that is often done is to see if a piece of data is a valid IP. A valid IP might be a string that simply meets the criteria of an IP, an IP that is on a specific network, an IP that defines a network, etc.
This module performs several IP releated checks.
This is the only function provided by this module, and it is intended to be used by the Data::Checker module.
This checks elements to see if they are valid IPv4 or IPv6 addresses using the NetAddr::IP module.
The $check_opts hashref defines exactly what IP checks to perform, and some options used by those checks. Known keys that specify the checks are:
$check_opts
If either of these options are given, the IP must be an IPv4 or IPv6 address respectively.
If either of these options are given, the IP must be a network IP or a broadcast IP. The IP should be specified in CIDR notation so that the mask can be determined. Alternately, if the network option is given, the IP must be the network or broadcast IP for that network.
The IP must belong to the network specified by the network option. The value must be any network definition accepted by NetAddr::IP.
The following options are supported.
This specifies the network that an IP should belong to (or NOT belong to if the negate option is used) with the in_network check.
use Data::Checker; $obj = new Data::Checker; $data = ... $opts = ... ($pass,$fail,$info,$warn) = $obj->check($data,"IP",$opts);
The value of $data and $opts is listed below in the examples.
$data
$opts
$data = [ '1.2.3.4', '1:2:3:4:5:6:7:8', 'some-string' ]; $opts = { }
This yields:
$pass = [ '1.2.3.4', '1:2:3:4:5:6:7:8' ]; $fail = { 'some-string' => 'Not a valid IP' }
$data = [ '1.2.3.4', '1:2:3:4:5:6:7:8' ]; $opts = { 'ipv4' => undef }
$data = [ '1.2.3.4', '10.20.30.40' ]; $opts = { 'in_network' { 'network' => '1.2.3.0/24' } };
None known.
Data::Checker, NetAddr::IP
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Sullivan Beck (sbeck@cpan.org)
To install Data::Checker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Checker
CPAN shell
perl -MCPAN -e shell install Data::Checker
For more information on module installation, please visit the detailed CPAN module installation guide.