• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bench/H17-Nov-2016-10180

lib/Data/Validate/H17-Nov-2016-881462

t/H17-Nov-2016-752605

xt/H17-Nov-2016-282198

CONTRIBUTING.mdH A D17-Nov-20164.1 KiB13287

ChangesH A D17-Nov-20166 KiB210118

INSTALLH A D17-Nov-20161.2 KiB4426

LICENSEH A D17-Nov-201617.9 KiB380292

MANIFESTH A D17-Nov-2016735 3938

META.jsonH A D17-Nov-201633.5 KiB1,0071,005

META.ymlH A D17-Nov-201621.3 KiB738737

Makefile.PLH A D17-Nov-20161.4 KiB6655

README.mdH A D17-Nov-20168 KiB251164

cpanfileH A D17-Nov-20161.5 KiB5247

dist.iniH A D17-Nov-2016561 2825

perlcriticrcH A D17-Nov-20161.8 KiB6847

perltidyrcH A D17-Nov-2016214 1413

test-vars-ignoreH A D17-Nov-201626 21

tidyall.iniH A D17-Nov-2016707 3633

README.md

1# NAME
2
3Data::Validate::IP - IPv4 and IPv6 validation methods
4
5# VERSION
6
7version 0.27
8
9# SYNOPSIS
10
11    use Data::Validate::IP qw(is_ipv4 is_ipv6);
12
13    my $suspect = '1.2.3.4';
14    if (is_ipv4($suspect)) {
15        print "Looks like an IPv4 address";
16    }
17    else {
18        print "Not an IPv4 address\n";
19    }
20
21    $suspect = '::1234';
22    if (is_ipv6($suspect)) {
23        print "Looks like an IPv6 address";
24    }
25    else {
26        print "Not an IPv6 address\n";
27    }
28
29# DESCRIPTION
30
31This module provides a number IP address validation subs that both validate
32and untaint their input. This includes both basic validation (`is_ipv4()` and
33`is_ipv6()`) and special cases like checking whether an address belongs to a
34specific network or whether an address is public or private (reserved).
35
36# FUNCTIONS
37
38All of the functions below are exported by default.
39
40All functions return an untainted value if the test passes and undef if it
41fails. In theory, this means that you should always check for a defined status
42explicitly but in practice there are no valid IP addresses where the string
43form evaluates to false in Perl.
44
45Note that none of these functions actually attempt to test whether the given
46IP address is routable from your device; they are purely semantic checks.
47
48## is\_ipv4($ip), is\_ipv6($ip), is\_ip($ip)
49
50These functions simply check whether the address is a valid IPv4 or IPv6 address.
51
52## is\_innet\_ipv4($ip, $network)
53
54This subroutine checks whether the address belongs to the given IPv4
55network. The `$network` argument can either be a string in CIDR notation like
56"15.0.15.0/24" or a [NetAddr::IP](https://metacpan.org/pod/NetAddr::IP) object.
57
58This subroutine used to accept many more forms of network specifications
59(anything [Net::Netmask](https://metacpan.org/pod/Net::Netmask) accepts) but this has been deprecated.
60
61## is\_unroutable\_ipv4($ip)
62
63This subroutine checks whether the address belongs to any of several special
64use IPv4 networks - `0.0.0.0/8`, `100.64.0.0/10`, `192.0.0.0/29`,
65`198.18.0.0/15`, `240.0.0.0/4` - as defined by [RFC
665735](http://tools.ietf.org/html/rfc5735), [RFC
676333](http://tools.ietf.org/html/rfc6333), and [RFC
686958](http://tools.ietf.org/html/rfc6598).
69
70Arguably, these should be broken down further but this subroutine will always
71exist for backwards compatibility.
72
73## is\_private\_ipv4($ip)
74
75This subroutine checks whether the address belongs to any of the private IPv4
76networks - `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` - as defined by
77[RFC 5735](http://tools.ietf.org/html/rfc5735).
78
79## is\_loopback\_ipv4($ip)
80
81This subroutine checks whether the address belongs to the IPv4 loopback
82network - `127.0.0.0/8` - as defined by [RFC
835735](http://tools.ietf.org/html/rfc5735).
84
85## is\_linklocal\_ipv4($ip)
86
87This subroutine checks whether the address belongs to the IPv4 link local
88network - `169.254.0.0/16` - as defined by [RFC
895735](http://tools.ietf.org/html/rfc5735).
90
91## is\_testnet\_ipv4($ip)
92
93This subroutine checks whether the address belongs to any of the IPv4 TEST-NET
94networks for use in documentation and example code - `192.0.2.0/24`,
95`198.51.100.0/24`, and `203.0.113.0/24` - as defined by [RFC
965735](http://tools.ietf.org/html/rfc5735).
97
98## is\_anycast\_ipv4($ip)
99
100This subroutine checks whether the address belongs to the 6to4 relay anycast
101network - `192.88.99.0/24` - as defined by [RFC
1025735](http://tools.ietf.org/html/rfc5735).
103
104## is\_multicast\_ipv4($ip)
105
106This subroutine checks whether the address belongs to the IPv4 multicast
107network - `224.0.0.0/4` - as defined by [RFC
1085735](http://tools.ietf.org/html/rfc5735).
109
110## is\_loopback\_ipv6($ip)
111
112This subroutine checks whether the address is the IPv6 loopback address -
113`::1/128` - as defined by [RFC 4291](http://tools.ietf.org/html/rfc4291).
114
115## is\_ipv4\_mapped\_ipv6($ip)
116
117This subroutine checks whether the address belongs to the IPv6 IPv4-mapped
118address network - `::ffff:0:0/96` - as defined by [RFC
1194291](http://tools.ietf.org/html/rfc4291).
120
121## is\_discard\_ipv6($ip)
122
123This subroutine checks whether the address belongs to the IPv6 discard prefix
124network - `100::/64` - as defined by [RFC
1256666](http://tools.ietf.org/html/rfc6666).
126
127## is\_special\_ipv6($ip)
128
129This subroutine checks whether the address belongs to the IPv6 special network
130\- `2001::/23` - as defined by [RFC 2928](http://tools.ietf.org/html/rfc2928).
131
132## is\_teredo\_ipv6($ip)
133
134This subroutine checks whether the address belongs to the IPv6 TEREDO network
135\- `2001::/32` - as defined by [RFC 4380](http://tools.ietf.org/html/rfc4380).
136
137Note that this network is a subnet of the larger special network at
138`2001::/23`.
139
140## is\_orchid\_ipv6($ip)
141
142This subroutine checks whether the address belongs to the IPv6 ORCHID network
143\- `2001::/32` - as defined by [RFC 4380](http://tools.ietf.org/html/rfc4380).
144
145Note that this network is a subnet of the larger special network at
146`2001::/23`.
147
148This network is currently scheduled to be returned to the special pool in
149March of 2014 unless the IETF extends its use. If that happens this subroutine
150will continue to exist but will always return false.
151
152## is\_documentation\_ipv6($ip)
153
154This subroutine checks whether the address belongs to the IPv6 documentation
155network - `2001:DB8::/32` - as defined by [RFC
1563849](http://tools.ietf.org/html/rfc3849).
157
158## is\_private\_ipv6($ip)
159
160This subroutine checks whether the address belongs to the IPv6 private network
161\- `FC00::/7` - as defined by [RFC 4193](http://tools.ietf.org/html/rfc4193).
162
163## is\_linklocal\_ipv6($ip)
164
165This subroutine checks whether the address belongs to the IPv6 link-local
166unicast network - `FE80::/10` - as defined by [RFC
1674291](http://tools.ietf.org/html/rfc4291).
168
169## is\_multicast\_ipv6($ip)
170
171This subroutine checks whether the address belongs to the IPv6 multicast
172network - `FF00::/8` - as defined by [RFC
1734291](http://tools.ietf.org/html/rfc4291).
174
175## is\_public\_ipv4($ip), is\_public\_ipv6($ip), is\_public\_ip($ip)
176
177These subroutines check whether the given IP address belongs to any of the
178special case networks defined previously. Note that this is **not** simply the
179opposite of checking `is_private_ipv4()` or `is_private_ipv6()`. The private
180networks are a subset of all the special case networks.
181
182## is\_linklocal\_ip($ip)
183
184This subroutine checks whether the address belongs to the IPv4 or IPv6
185link-local unicast network.
186
187## is\_loopback\_ip($ip)
188
189This subroutine checks whether the address is the IPv4 or IPv6 loopback
190address.
191
192## is\_multicast\_ip($ip)
193
194This subroutine checks whether the address belongs to the IPv4 or IPv6
195multicast network.
196
197## is\_private\_ip($ip)
198
199This subroutine checks whether the address belongs to the IPv4 or IPv6 private
200network.
201
202# OBJECT-ORIENTED INTERFACE
203
204This module can also be used as a class. You can call `Data::Validate::IP->new()` to get an object and then call any of the
205validation subroutines as methods on that object. This is somewhat pointless
206since the object will never contain any state but this interface is kept for
207backwards compatibility.
208
209# SEE ALSO
210
211IPv4
212
213**\[RFC 5735\] \[RFC 1918\]**
214
215IPv6
216
217**\[RFC 2460\] \[RFC 4193\] \[RFC 4291\] \[RFC 6434\]**
218
219# ACKNOWLEDGEMENTS
220
221Thanks to Richard Sonnen <`sonnen@richardsonnen.com`> for writing the
222Data::Validate module.
223
224Thanks to Matt Dainty <`matt@bodgit-n-scarper.com`> for adding the
225`is_multicast_ipv4()` and `is_linklocal_ipv4()` code.
226
227# BUGS
228
229Please report any bugs or feature requests to
230`bug-data-validate-ip@rt.cpan.org`, or through the web interface at
231[http://rt.cpan.org](http://rt.cpan.org). I will be notified, and then you'll automatically be
232notified of progress on your bug as I make changes.
233
234Bugs may be submitted through [https://github.com/houseabsolute/Data-Validate-IP/issues](https://github.com/houseabsolute/Data-Validate-IP/issues).
235
236# AUTHORS
237
238- Neil Neely <neil@neely.cx>
239- Dave Rolsky <autarch@urth.org>
240
241# CONTRIBUTOR
242
243Gregory Oschwald <goschwald@maxmind.com>
244
245# COPYRIGHT AND LICENSE
246
247This software is copyright (c) 2016 by Neil Neely.
248
249This is free software; you can redistribute it and/or modify it under
250the same terms as the Perl 5 programming language system itself.
251