.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Data::Validate::IP 3pm" .TH Data::Validate::IP 3pm "2016-12-28" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Validate::IP \- IPv4 and IPv6 validation methods .SH "VERSION" .IX Header "VERSION" version 0.27 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Validate::IP qw(is_ipv4 is_ipv6); \& \& my $suspect = \*(Aq1.2.3.4\*(Aq; \& if (is_ipv4($suspect)) { \& print "Looks like an IPv4 address"; \& } \& else { \& print "Not an IPv4 address\en"; \& } \& \& $suspect = \*(Aq::1234\*(Aq; \& if (is_ipv6($suspect)) { \& print "Looks like an IPv6 address"; \& } \& else { \& print "Not an IPv6 address\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a number \s-1IP\s0 address validation subs that both validate and untaint their input. This includes both basic validation (\f(CW\*(C`is_ipv4()\*(C'\fR and \&\f(CW\*(C`is_ipv6()\*(C'\fR) and special cases like checking whether an address belongs to a specific network or whether an address is public or private (reserved). .SH "FUNCTIONS" .IX Header "FUNCTIONS" All of the functions below are exported by default. .PP All functions return an untainted value if the test passes and undef if it fails. In theory, this means that you should always check for a defined status explicitly but in practice there are no valid \s-1IP\s0 addresses where the string form evaluates to false in Perl. .PP Note that none of these functions actually attempt to test whether the given \&\s-1IP\s0 address is routable from your device; they are purely semantic checks. .SS "is_ipv4($ip), is_ipv6($ip), is_ip($ip)" .IX Subsection "is_ipv4($ip), is_ipv6($ip), is_ip($ip)" These functions simply check whether the address is a valid IPv4 or IPv6 address. .ie n .SS "is_innet_ipv4($ip, $network)" .el .SS "is_innet_ipv4($ip, \f(CW$network\fP)" .IX Subsection "is_innet_ipv4($ip, $network)" This subroutine checks whether the address belongs to the given IPv4 network. The \f(CW$network\fR argument can either be a string in \s-1CIDR\s0 notation like \&\*(L"15.0.15.0/24\*(R" or a NetAddr::IP object. .PP This subroutine used to accept many more forms of network specifications (anything Net::Netmask accepts) but this has been deprecated. .SS "is_unroutable_ipv4($ip)" .IX Subsection "is_unroutable_ipv4($ip)" This subroutine checks whether the address belongs to any of several special use IPv4 networks \- \f(CW\*(C`0.0.0.0/8\*(C'\fR, \f(CW\*(C`100.64.0.0/10\*(C'\fR, \f(CW\*(C`192.0.0.0/29\*(C'\fR, \&\f(CW\*(C`198.18.0.0/15\*(C'\fR, \f(CW\*(C`240.0.0.0/4\*(C'\fR \- as defined by \s-1RFC 5735\s0 , \s-1RFC 6333\s0 , and \s-1RFC 6958\s0 . .PP Arguably, these should be broken down further but this subroutine will always exist for backwards compatibility. .SS "is_private_ipv4($ip)" .IX Subsection "is_private_ipv4($ip)" This subroutine checks whether the address belongs to any of the private IPv4 networks \- \f(CW\*(C`10.0.0.0/8\*(C'\fR, \f(CW\*(C`172.16.0.0/12\*(C'\fR, \f(CW\*(C`192.168.0.0/16\*(C'\fR \- as defined by \&\s-1RFC 5735\s0 . .SS "is_loopback_ipv4($ip)" .IX Subsection "is_loopback_ipv4($ip)" This subroutine checks whether the address belongs to the IPv4 loopback network \- \f(CW\*(C`127.0.0.0/8\*(C'\fR \- as defined by \s-1RFC 5735\s0 . .SS "is_linklocal_ipv4($ip)" .IX Subsection "is_linklocal_ipv4($ip)" This subroutine checks whether the address belongs to the IPv4 link local network \- \f(CW\*(C`169.254.0.0/16\*(C'\fR \- as defined by \s-1RFC 5735\s0 . .SS "is_testnet_ipv4($ip)" .IX Subsection "is_testnet_ipv4($ip)" This subroutine checks whether the address belongs to any of the IPv4 TEST-NET networks for use in documentation and example code \- \f(CW\*(C`192.0.2.0/24\*(C'\fR, \&\f(CW\*(C`198.51.100.0/24\*(C'\fR, and \f(CW\*(C`203.0.113.0/24\*(C'\fR \- as defined by \s-1RFC 5735\s0 . .SS "is_anycast_ipv4($ip)" .IX Subsection "is_anycast_ipv4($ip)" This subroutine checks whether the address belongs to the 6to4 relay anycast network \- \f(CW\*(C`192.88.99.0/24\*(C'\fR \- as defined by \s-1RFC 5735\s0 . .SS "is_multicast_ipv4($ip)" .IX Subsection "is_multicast_ipv4($ip)" This subroutine checks whether the address belongs to the IPv4 multicast network \- \f(CW\*(C`224.0.0.0/4\*(C'\fR \- as defined by \s-1RFC 5735\s0 . .SS "is_loopback_ipv6($ip)" .IX Subsection "is_loopback_ipv6($ip)" This subroutine checks whether the address is the IPv6 loopback address \- \&\f(CW\*(C`::1/128\*(C'\fR \- as defined by \s-1RFC 4291\s0 . .SS "is_ipv4_mapped_ipv6($ip)" .IX Subsection "is_ipv4_mapped_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 IPv4\-mapped address network \- \f(CW\*(C`::ffff:0:0/96\*(C'\fR \- as defined by \s-1RFC 4291\s0 . .SS "is_discard_ipv6($ip)" .IX Subsection "is_discard_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 discard prefix network \- \f(CW\*(C`100::/64\*(C'\fR \- as defined by \s-1RFC 6666\s0 . .SS "is_special_ipv6($ip)" .IX Subsection "is_special_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 special network \&\- \f(CW\*(C`2001::/23\*(C'\fR \- as defined by \s-1RFC 2928\s0 . .SS "is_teredo_ipv6($ip)" .IX Subsection "is_teredo_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 \s-1TEREDO\s0 network \&\- \f(CW\*(C`2001::/32\*(C'\fR \- as defined by \s-1RFC 4380\s0 . .PP Note that this network is a subnet of the larger special network at \&\f(CW\*(C`2001::/23\*(C'\fR. .SS "is_orchid_ipv6($ip)" .IX Subsection "is_orchid_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 \s-1ORCHID\s0 network \&\- \f(CW\*(C`2001::/32\*(C'\fR \- as defined by \s-1RFC 4380\s0 . .PP Note that this network is a subnet of the larger special network at \&\f(CW\*(C`2001::/23\*(C'\fR. .PP This network is currently scheduled to be returned to the special pool in March of 2014 unless the \s-1IETF\s0 extends its use. If that happens this subroutine will continue to exist but will always return false. .SS "is_documentation_ipv6($ip)" .IX Subsection "is_documentation_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 documentation network \- \f(CW\*(C`2001:DB8::/32\*(C'\fR \- as defined by \s-1RFC 3849\s0 . .SS "is_private_ipv6($ip)" .IX Subsection "is_private_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 private network \&\- \f(CW\*(C`FC00::/7\*(C'\fR \- as defined by \s-1RFC 4193\s0 . .SS "is_linklocal_ipv6($ip)" .IX Subsection "is_linklocal_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 link-local unicast network \- \f(CW\*(C`FE80::/10\*(C'\fR \- as defined by \s-1RFC 4291\s0 . .SS "is_multicast_ipv6($ip)" .IX Subsection "is_multicast_ipv6($ip)" This subroutine checks whether the address belongs to the IPv6 multicast network \- \f(CW\*(C`FF00::/8\*(C'\fR \- as defined by \s-1RFC 4291\s0 . .SS "is_public_ipv4($ip), is_public_ipv6($ip), is_public_ip($ip)" .IX Subsection "is_public_ipv4($ip), is_public_ipv6($ip), is_public_ip($ip)" These subroutines check whether the given \s-1IP\s0 address belongs to any of the special case networks defined previously. Note that this is \fBnot\fR simply the opposite of checking \f(CW\*(C`is_private_ipv4()\*(C'\fR or \f(CW\*(C`is_private_ipv6()\*(C'\fR. The private networks are a subset of all the special case networks. .SS "is_linklocal_ip($ip)" .IX Subsection "is_linklocal_ip($ip)" This subroutine checks whether the address belongs to the IPv4 or IPv6 link-local unicast network. .SS "is_loopback_ip($ip)" .IX Subsection "is_loopback_ip($ip)" This subroutine checks whether the address is the IPv4 or IPv6 loopback address. .SS "is_multicast_ip($ip)" .IX Subsection "is_multicast_ip($ip)" This subroutine checks whether the address belongs to the IPv4 or IPv6 multicast network. .SS "is_private_ip($ip)" .IX Subsection "is_private_ip($ip)" This subroutine checks whether the address belongs to the IPv4 or IPv6 private network. .SH "OBJECT-ORIENTED INTERFACE" .IX Header "OBJECT-ORIENTED INTERFACE" This module can also be used as a class. You can call \f(CW\*(C`Data::Validate::IP\->new()\*(C'\fR to get an object and then call any of the validation subroutines as methods on that object. This is somewhat pointless since the object will never contain any state but this interface is kept for backwards compatibility. .SH "SEE ALSO" .IX Header "SEE ALSO" IPv4 .PP \&\fB[\s-1RFC 5735\s0] [\s-1RFC 1918\s0]\fR .PP IPv6 .PP \&\fB[\s-1RFC 2460\s0] [\s-1RFC 4193\s0] [\s-1RFC 4291\s0] [\s-1RFC 6434\s0]\fR .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to Richard Sonnen <\fIsonnen@richardsonnen.com\fR> for writing the Data::Validate module. .PP Thanks to Matt Dainty <\fImatt@bodgit\-n\-scarper.com\fR> for adding the \&\f(CW\*(C`is_multicast_ipv4()\*(C'\fR and \f(CW\*(C`is_linklocal_ipv4()\*(C'\fR code. .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-data\-validate\-ip@rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .PP Bugs may be submitted through . .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Neil Neely .IP "\(bu" 4 Dave Rolsky .SH "CONTRIBUTOR" .IX Header "CONTRIBUTOR" Gregory Oschwald .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2016 by Neil Neely. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.