perldoc > NetAddr::IP

📖 NAME

NetAddr::IP — Manages IPv4 and IPv6 addresses and subnets

🚀 Quick Reference

Use CaseCommandDescription
Create IP objectmy $ip = NetAddr::IP->new('192.168.1.1/24');🎯 Create an IP object with address and optional mask
Check subnet containment$ip->contains($other)🔍 Returns true if $ip completely contains $other
Compact subnetsCompact(@subnets)📦 Returns minimal set of subnets covering all given
Split subnet$ip->split(28)✂️ Split subnet into smaller subnets of specified mask length
Get broadcast address$ip->broadcast()📡 Returns broadcast address of subnet
Enumerate hosts$ip->hostenum()👥 Returns list of all host addresses in subnet
Get nth host$ip->nth(5)🔢 Returns 5th usable host address
Check RFC1918$ip->is_rfc1918()🏠 Returns true if address is private (RFC1918)
Stringify to CIDRprint "$ip\n"🖨️ Prints address in CIDR notation (e.g., 192.168.1.1/24)

📋 SYNOPSIS

use NetAddr::IP qw(
      Compact
      Coalesce
      Zeros
      Ones
      V4mask
      V4net
      netlimit
      :aton           DEPRECATED
      :lower
      :upper
      :old_storable
      :old_nth
      :rfc3021
      :nofqdn
);

NOTE: NetAddr::IP::Util has a full complement of network address utilities to convert back and forth between binary and text.

inet_aton, inet_ntoa, ipv6_aton, ipv6_ntoa
ipv6_n2x, ipv6_n2d inet_any2d, inet_n2dx,
inet_n2ad, inetanyto6, ipv6to4

See NetAddr::IP::Util

my $ip = new NetAddr::IP '127.0.0.1';
     or if you prefer
my $ip = NetAddr::IP->new('127.0.0.1);
    or from a packed IPv4 address
my $ip = new_from_aton NetAddr::IP (inet_aton('127.0.0.1'));
    or from an octal filtered IPv4 address
my $ip = new_no NetAddr::IP '127.012.0.0';

print "The address is ", $ip->addr, " with mask ", $ip->mask, "\n" ;

if ($ip->within(new NetAddr::IP "127.0.0.0", "255.0.0.0")) {
    print "Is a loopback address\n";
}

                                    # This prints 127.0.0.1/32
print "You can also say $ip...\n";

* The following four functions return ipV6 representations of:

::                                       = Zeros();
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF  = Ones();
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF::          = V4mask();
::FFFF:FFFF                              = V4net();

Will also return an ipV4 or ipV6 representation of a resolvable Fully Qualified Domain Name (FQDN).

###### DEPRECATED, will be removed in version 5 ############

* To accept addresses in the format as returned by inet_aton, invoke the module as:

use NetAddr::IP qw(:aton);

###### USE new_from_aton instead ##########################

* To enable usage of legacy data files containing NetAddr::IP objects stored using the Storable module.

use NetAddr::IP qw(:old_storable);

* To compact many smaller subnets (see: "$me->compact($addr1,$addr2,...)"

@compacted_object_list = Compact(@object_list)

* Return a reference to list of "NetAddr::IP" subnets of $masklen mask length, when $number or more addresses from @list_of_subnets are found to be contained in said subnet.

$arrayref = Coalesce($masklen, $number, @list_of_subnets)

* By default NetAddr::IP functions and methods return string IPv6 addresses in uppercase. To change that to lowercase:

NOTE: the AUGUST 2010 RFC5952 states:

4.3. Lowercase
The characters "a", "b", "c", "d", "e", and "f" in an IPv6 address MUST be represented in lowercase.

It is recommended that all NEW applications using NetAddr::IP be invoked as shown on the next line.

use NetAddr::IP qw(:lower);

* To ensure the current IPv6 string case behavior even if the default changes:

use NetAddr::IP qw(:upper);

* To set a limit on the size of nets processed or returned by NetAddr::IP.

Set the maximum number of nets beyond which NetAddr::IP will return an error as a power of 2 (default 16 or 65536 nets). Each 2**16 consumes approximately 4 megs of memory. A 2**20 consumes 64 megs of memory, A 2**24 consumes 1 gigabyte of memory.

use NetAddr::IP qw(netlimit);
netlimit 20;

The maximum netlimit allowed is 2**24. Attempts to set limits below the default of 16 or above the maximum of 24 are ignored.

Returns true on success, otherwise "undef".

🛠️ INSTALLATION

Un-tar the distribution in an appropriate directory and type:

perl Makefile.PL
make
make test
make install

NetAddr::IP depends on NetAddr::IP::Util which installs by default with its primary functions compiled using Perl's XS extensions to build a C library. If you do not have a C compiler available or would like the slower Pure Perl version for some other reason, then type:

perl Makefile.PL -noxs
make
make test
make install

📝 DESCRIPTION

This module provides an object-oriented abstraction on top of IP addresses or IP subnets that allows for easy manipulations. Version 4.xx of NetAddr::IP will work with older versions of Perl and is compatible with Math::BigInt.

The internal representation of all IP objects is in 128 bit IPv6 notation. IPv4 and IPv6 objects may be freely mixed.

⚡ Overloaded Operators

Many operators have been overloaded, as described below:

💾 Serializing and Deserializing

This module defines hooks to collaborate with Storable for serializing "NetAddr::IP" objects, through compact and human readable strings. You can revert to the old format by invoking this module as

use NetAddr::IP ':old_storable';

You must do this if you have legacy data files containing NetAddr::IP objects stored using the Storable module.

🔧 Methods

📤 EXPORT_OK

📝 NOTES / BUGS ... FEATURES

NetAddr::IP only runs in Pure Perl mode on Windows boxes because I don't have the resources or know how to get the "configure" stuff working in the Windows environment. Volunteers WELCOME to port the "C" portion of this module to Windows.

📜 HISTORY

See the Changes file

👤 AUTHORS

Luis E. Muñoz <luismunoz AT cpan.org>, Michael Robinton <michael AT bizsystems.com>

⚖️ WARRANTY

This software comes with the same warranty as Perl itself (ie, none), so by using it you accept any and all the liability.

📄 COPYRIGHT

This software is (c) Luis E. Muñoz, 1999 - 2007, and (c) Michael Robinton, 2006 - 2014.

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of either:

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.

You should have received a copy of the Artistic License with this distribution, in the file named "Artistic". If not, I'll be glad to provide one.

You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the

Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301 USA.

or visit their web page on the internet at:

http://www.gnu.org/copyleft/gpl.html.

🔗 SEE ALSO

perl(1), NetAddr::IP::Lite, NetAddr::IP::Util, NetAddr::IP::InetBase

NetAddr::IP
📖 NAME 🚀 Quick Reference 📋 SYNOPSIS 🛠️ INSTALLATION 📝 DESCRIPTION
⚡ Overloaded Operators 💾 Serializing and Deserializing 🔧 Methods
📤 EXPORT_OK 📝 NOTES / BUGS ... FEATURES 📜 HISTORY 👤 AUTHORS ⚖️ WARRANTY 📄 COPYRIGHT 🔗 SEE ALSO

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-27 17:42 @216.73.216.199
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^