NetAddr...InetBase(3)
π¦ NetAddr::IP::InetBase(3) β the Perl manual page, bestie edition π¦
okay so this is the NetAddr...InetBase(3) page from the User Contributed Perl Documentation β we're talking IPv4 and IPv6 utilities and honestly? it's giving infrastructure fairy godmother β¨
π NAME
NetAddr::IP::InetBase β IPv4 and IPV6 utilities. that's it, that's the whole vibe. no cap.
πΈ SYNOPSIS
like, here's how you actually pull it in:
use NetAddr::IP::Base qw(
:upper
inet_aton
inet_ntoa
ipv6_aton
ipv6_ntoa
ipv6_n2x
ipv6_n2d
inet_any2n
inet_n2dx
inet_n2ad
inet_pton
inet_ntop
packzeros
isIPv4
isNewIPv4
isAnyIPv4
AF_INET
AF_INET6
fake_AF_INET6
fillIPv4
);
use NetAddr::IP::Util qw(:all :inet :ipv4 :ipv6 :math)
:ipv4 => inet_aton, inet_ntoa, fillIPv4
:ipv6 => ipv6_aton, ipv6_ntoa,ipv6_n2x, ipv6_n2d,
inet_any2n, inet_n2dx, inet_n2ad
inet_pton, inet_ntop, packzeros
$dotquad = inet_ntoa($netaddr);
$netaddr = inet_aton($dotquad);
$ipv6naddr = ipv6_aton($ipv6_text);
$ipv6_text = ipv6_ntoa($ipv6naddr);
$hex_text = ipv6_n2x($ipv6naddr);
$dec_text = ipv6_n2d($ipv6naddr);
$ipv6naddr = inet_any2n($dotquad or $ipv6_text);
$dotquad or $hex_text = inet_n2dx($ipv6naddr);
$dotquad or $dec_text = inet_n2ad($ipv6naddr);
$netaddr = inet_pton($AF_family,$text_addr);
$text_addr = inet_ntop($AF_family,$netaddr);
$hex_text = packzeros($hex_text);
$rv = isIPv4($bits128);
$rv = isNewIPv4($bits128);
$rv = isAnyIPv4($bits128);
$constant = AF_INET();
$constant = AF_INET6();
$trueif = fake_AF_INET6();
$ip_filled = fillIPv4($shortIP);
NetAddr::IP::InetBase::lower();
NetAddr::IP::InetBase::upper();
and yes, you also toggle the case vibes directly:
NetAddr::IP::InetBase::lower();
NetAddr::IP::InetBase::upper();
π INSTALLATION
un-tar the distribution in an appropriate directory and then, bestie, run these in order β no skipping π
perl Makefile.PL
make
make test
make install
make test is not optional, i don't make the rules (i do, actually, and i'm saying run it).
β¨ DESCRIPTION
so NetAddr::IP::InetBase hands you a whole suite network of conversion functions, written in pure Perl, for flipping both IPv4 and IPv6 addresses to and from network address format and text format. it's the translator bestie of the IP world π«Ά
the IPv6 functions support all rfc1884 formats. like:
i.e. x:x:x:x:x:x:x:x:x
x:x:x:x:x:x:x:d.d.d.d
::x:x:x
::x:d.d.d.d
and so on... you get it π
$dotquad = inet_ntoa($netaddr);β converts a packed IPv4 network address into a dot-quad IP address.
input: packed network address
returns: IP address i.e. 10.4.12.123
$netaddr = inet_aton($dotquad);β converts a dot-quad IP address into an IPv4 packed network address.
input: IP address i.e. 192.5.16.32
returns: packed network address
$ipv6addr = ipv6_aton($ipv6_text);β takes an IPv6 address of the form described in rfc1884 and returns a 128 bit binary RDATA string.
input: ipv6 text
returns: 128 bit RDATA string
$ipv6text = ipv6_ntoa($ipv6naddr);β converts a 128 bit binary IPv6 address into compressed rfc 1884 text representation. compression slay π
input: 128 bit RDATA string
returns: ipv6 text
$hex_text = ipv6_n2x($ipv6addr);β takes an IPv6 RDATA string and returns an 8 segment IPv6 hex address.
input: 128 bit RDATA string
returns: x:x:x:x:x:x:x:x
Note: this function does NOT compress adjacent
strings of 0:0:0:0 into the :: format
okay important: this one does NOT compress adjacent strings of0:0:0:0into the::format. read it and weep π
$dec_text = ipv6_n2d($ipv6addr);β takes an IPv6 RDATA string and returns a mixed hex-decimal IPv6 address, with the 6 uppermost chunks in hex and the lower 32 bits in dot-quad representation. hybrid icon behavior π
input: 128 bit RDATA string
returns: x:x:x:x:x:x:d.d.d.d
Note: this function does NOT compress adjacent
strings of 0:0:0:0 into the :: format
again: NOT compressing. same energy. don't come for me, i'm just the messenger π§
$ipv6naddr = inet_any2n($dotquad or $ipv6_text);β converts a text IPv4 or IPv6 address in text format in any standard notation into a 128 bit IPv6 string address. it prefixes any dot-quad address (if found) with'::'and passes it toipv6_aton. truly the "idk what you gave me but i'll handle it" friend π
input: dot-quad or rfc1844 address
returns: 128 bit IPv6 string
$dotquad or $hex_text = inet_n2dx($ipv6naddr);β this function does the right thing and returns the text for either a dot-quad IPv4 or a hex notation IPv6 address. main character energy, it just knows π₯
input: 128 bit IPv6 string
returns: ddd.ddd.ddd.ddd
or x:x:x:x:x:x:x:x
Note: this function does NOT compress adjacent
strings of 0:0:0:0 into the :: format
yes bestie, still NOT compressing. it's a whole theme π
$dotquad or $dec_text = inet_n2ad($ipv6naddr);β this function does the right thing and returns the text for either a dot-quad IPv4 or a hex::decimal notation IPv6 address.
input: 128 bit IPv6 string
returns: ddd.ddd.ddd.ddd
or x:x:x:x:x:x:ddd.ddd.ddd.dd
Note: this function does NOT compress adjacent
strings of 0:0:0:0 into the :: format
one more time for the people in the back: NOT compressing π
$netaddr = inet_pton($AF_family,$text_addr);β takes an IP address in IPv4 or IPv6 text format and converts it into binary format. the type of IP address conversion is controlled by theFAMILYargument. you're in charge, periodt π
NOTE:inet_pton,inet_ntopandAF_INET6come from theSocket6library if it is present on this host.
$text_addr = inet_ntop($AF_family,$netaddr);β takes and IP address in binary format and converts it into text format. the type of IP address conversion is controlled by theFAMILYargument.
NOTE:inet_ntopALWAYS returns lowercase characters. NOTE:inet_pton,inet_ntopandAF_INET6come from theSocket6library if it is present on this host.
$hex_text = packzeros($hex_text);β this function optimizes and rfc 1884 IPv6 hex address to reduce the number of long strings of zero bits as specified in rfc 1884, 2.2 (2) by substituting::for the first occurence of the longest string of zeros in the address. finally, the compression we've been waiting for β$ipv6naddr = ipv4to6($netaddr);β convert an ipv4 network address into an ipv6 network address. glow-up complete π¦
input: 32 bit network address
returns: 128 bit network address
$rv = isIPv4($bits128);β returns true if there are no on bits present in the IPv6 portion of the 128 bit string, and false otherwise.
i.e. the address must be of the form - ::d.d.d.d
Note: this is an old and deprecated ipV4 compatible ipV6 address. deprecated, bestie β treat it like an old flip phone, cute but don't rely on it π
$rv = isNewIPv4($bits128);β returns true if the IPv6 128 bit string is of the form:
::ffff:d.d.d.d
$rv = isAnyIPv4($bits128);β returns true if the IPv6 bit string is of the form:
::d.d.d.d or ::ffff:d.d.d.d
NetAddr::IP::InetBase::lower();β return IPv6 strings in lowercase. this is the default. chill, lowercase, cozy πΈNetAddr::IP::InetBase::upper();β return IPv6 strings in uppercase. LOUD MODE π£
the default may be set to uppercase when the module is loaded by invoking the TAG :upper. i.e.
use NetAddr::IP::InetBase qw( :upper );
$constant = AF_INET;β this function returns the system value forAF_INET.$constant = AF_INET6;βAF_INET6is sometimes present in theSocketlibrary and always present in theSocket6library. when theSocketlibrary does not containAF_INET6and whenSocket6is not present, a place holder value is "guessed" based on the underlying host operating system. seefake_AF_INET6below. it's giving detective work π
NOTE:inet_pton,inet_ntopandAF_INET6come from theSocket6library if it is present on this host.
$trueif = fake_AF_INET6;β this function return FALSE ifAF_INET6is provided bySocketorSocket6. otherwise, it returns the best guess value based on name of the host operating system. π§$ip_filled = fillIPv4($shortIP);β converts IPv4 addresses of the form127.1to the long form127.0.0.1. stretch that address out, bestie π
if the function is passed an argument that does not match the form of an IP address, the original argument is returned. i.e. pass it a hostname or a short IP and it will return a hostname or a filled IP. no notes, it just doesn't touch what isn't its business π«Ά
π EXPORT_OK
:upper
inet_aton
inet_ntoa
ipv6_aton
ipv6_ntoa
ipv6_n2x
ipv6_n2d
inet_any2n
inet_n2dx
inet_n2ad
inet_pton
inet_ntop
packzeros
isIPv4
isNewIPv4
isAnyIPv4
AF_INET
AF_INET6
fake_AF_INET6
fillIPv4
π« %EXPORT_TAGS
:all
:ipv4
:ipv6
:upper
π AUTHOR
Michael Robinton <michael@bizsystems.com> β the icon who wrote all this β¨
π COPYRIGHT
Copyright 2003 - 2012, Michael Robinton <michael@bizsystems.com>
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of either:
- the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or
- the "Artistic License" which comes with this distribution.
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. (yes, all caps, they mean it π€)
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.
π§ AUTHOR
Michael Robinton <michael@bizsystems.com> β yes, again. credited twice, deservedly π
π SEE ALSO
NetAddr::IP(3), NetAddr::IP::Lite(3), NetAddr::IP::Util(3) β go read the whole friend group, iykyk π«Ά
β¨ cute sign-off β¨ this page is fromperl v5.42.0, dated2016-05-28, and it's theNetAddr...InetBase(3)page in the User Contributed Perl Documentation. now go convert some addresses, bestie β you're gonna slay π π
π¦ where this page comes from
- opensuse-leap 16.0: perl-NetAddr-IP 4.079-bp160.1.13 Β· Artistic-1.0 or GPL-1.0+
- opensuse-leap 16.0: perl-NetAddr-IP 4.079-bp160.1.13 Β· Artistic-1.0 or GPL-1.0+
- opensuse-leap 16.0: perl-NetAddr-IP 4.079-bp160.1.13 Β· Artistic-1.0 or GPL-1.0+
- opensuse-leap 16.0: perl-NetAddr-IP 4.079-bp160.1.13 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms