Sullivan Beck
and 1 contributors


Data::Checker::IP - check data to see if it is a valid IP


   use Data::Checker;
   $obj = new Data::Checker;



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:

ipv4, ipv6

If either of these options are given, the IP must be an IPv4 or IPv6 address respectively.

network_ip, broadcast_ip

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.

To check that the values are valid IPs
   $data = [ '', '1:2:3:4:5:6:7:8', 'some-string' ];
   $opts = { }

This yields:

   $pass = [ '', '1:2:3:4:5:6:7:8' ];
   $fail = { 'some-string' => 'Not a valid IP' }
To check if an IP is a valid IPv4
   $data = [ '', '1:2:3:4:5:6:7:8' ];
   $opts = { 'ipv4' => undef }
To check that all of the IPs are contained in a specific network
   $data = [ '', '' ];
   $opts = { 'in_network' { 'network' => '' } };


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 (