Parano...k::IPv6(3pm)

πŸ“¦
version 2.10 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Paranoid::Network::IPv6 β€” IPv6-related functions ✨

(yeah bestie, that's the one, straight out of the User Contributed Perl Documentation, section 3pm πŸŽ€)


πŸ’œ VERSION πŸ’œ

$Id: lib/Paranoid/Network/IPv6.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $

Like, that's it, that's the whole vibe check. Version 2.10. πŸ’…


🌸 SYNOPSIS 🌸

okay so first, the basic entrance:

use Paranoid::Network::IPv6;

@net = ipv6NetConvert($netAddr);
$rv = ipv6NetIntersect($net1, $net2);

or, if you want everything, main character style πŸ‘‘

use Paranoid::Network::IPv6 qw(:all);

print "Valid IP address\n" if $netAddr =~ /^@{[ IPV6REGEX ]}$/;

@net = ipv6NetConvert($netAddr);
$broadcast = $net[IPV6BRDCST];

and if you're only here for the sorting (respect, honestly):

use Paranoid::Network::IPv6 qw(:ipv6Sort);

@nets = sort ipv6StrSort    @nets;
@nets = sort ipv6PackedSort @nets;
@nets = sort ipv6NumSort    @nets;

πŸ¦‹ DESCRIPTION πŸ¦‹

This module is literally just a little bag of convenience functions for working with IPv6 addresses. No drama, no cap, just helpers so you don't have to do it all by hand. πŸ’–


🌈 IMPORT LISTS 🌈

By default you get these three, automatically, no asking required:

ipv6NetConvert ipv6NetPacked ipv6NetIntersect

And then there are the specialized import lists, for when you want to be specific:

  • base β€” members: @defaults
  • constants β€” members: MAXIPV6CIDR IPV6REGEX IPV6CIDRRGX IPV6BASE IPV6BRDCST IPV6MASK
  • ipv6Sort β€” members: ipv6StrSort ipv6PackedSort ipv6NumSort
  • all β€” members: @base @constants @ipv6Sort

✨ SUBROUTINES/METHODS ✨

πŸŽ€ ipv6NetConvert

@net = ipv6NetConvert($netAddr);

So this one takes an IPv4 network address in string format and converts it into an array of arrays. (Yes bestie, the docs really do say IPv4 right there β€” I am but the messenger πŸ’€.) Those inner arrays hold the base network address, the broadcast address, and the netmask, each one chopped up into native 32bit integer format chunks. Every sub array is basically exactly what you'd get out of this:

@chunks = unpack 'NNNN', inet_pton(AF_INET6, '::1');

with '::1' being the sample IPv6 address there. ::1 representation, iconic honestly.

The network address has to have the netmask in CIDR format, okay? Non-negotiable. And if you're passing a single IP address, the array will only have one subarray β€” just the IP itself, split into those 32bit integers.

Now the rough part: if you pass any argument that isn't a string representation of an IP address β€” including undef values β€” this function hands you back an empty array. Empty. Nothing. Gone. πŸ™ˆ

πŸŽ€ ipv6NetPacked

@net = ipv6NetPacked('fe80::/64');

This one is a wrapper around ipv6NetConvert, but instead of subarrays, each element is the packed (opaque) string, exactly as returned by inet_pton. Same energy, different shape. πŸ’…

πŸŽ€ ipv6NetIntersect

$rv = ipv6NetIntersect($net1, $net2);

This function tests whether an IP or subnet intersects with another IP or subnet. The return value is essentially boolean, but the true value can vary to tell you which one is a subset of the other:

-1: destination range encompasses target range
 0: both ranges do not intersect at all
 1: target range encompasses destination range

It handles the very same string formats as ipv6NetConvert, but here's the glow-up: it'll also let you test single IPs in integer format. 🫢

πŸŽ€ ipv6StrSort

@sorted = sort ipv6StrSort @nets;

Lets you pass IPv6 addresses and networks in string format. Networks can be in CIDR format. Sorts in ascending order. And yes, the docs literally end that sentence with :w and I am keeping every single character because the rules are the rules 😭

πŸŽ€ ipv6PackedSort

@sorted = sort ipv6PackedSort @nets;

Sorts addresses that are in packed format, like the ones inet_pton gives you. Ascending order, always. ⭐

πŸŽ€ ipv6NumSort

@sorted = sort ipv6NumSort @nets;

Sorts addresses that are in unpacked, native integer format β€” the kind you get from this:

@ip = unpack 'NNNN', inet_pton(AF_INET6, $ipAddr);

Sorts in ascending order. Heads up though: the list of addresses should be a list of lists. πŸ“š


πŸ‘‘ CONSTANTS πŸ‘‘

These cuties only get imported if you explicitly ask for them, or if you use the :all tag. No sneaky auto-importing here. πŸ’–

🧚 MAXIPV6CIDR

Simply put: 128. That's the largest CIDR notation supported in IPv6. Periodt.

🧚 IPV6REGEX

A regular expression. πŸŽ€

You can use this for validating IP addresses like so:

$ip =~ m#^@{[ IPV6REGEX ]}$#;

or to extract potential IPs from extraneous text:

@ips = ( $string =~ m#(@{[ IPV6REGEX ]})#g);

🧚 IPV6CIDRRGX

A regular expression. By default this will extract CIDR notation network addresses:

@networks = ( $string =~ m#(@{[ IPV6CIDRRGX ]})#si );

🧚 IPV6BASE

This is the ordinal index of the base network address, as returned by ipv6NetConvert.

🧚 IPV6BRDCST

This is the ordinal index of the broadcast address, as returned by ipv6NetConvert.

🧚 IPV6MASK

This is the ordinal index of the network mask, as returned by ipv6NetConvert.


πŸ’€ DEPENDENCIES πŸ’€

This module leans on its friends, fr fr:

  • Paranoid
  • Paranoid::Debug
  • Paranoid::Network::Socket

🌈 BUGS AND LIMITATIONS 🌈

...it's literally blank bestie. Nothing listed. No known bugs, no stated limitations, an empty page of possibilities. Not me being suspicious of that, ngl. πŸ‘€


πŸ’œ AUTHOR πŸ’œ

Arthur Corliss (corliss@digitalmages.com)


This software is free software. Similar to Perl, you can redistribute it and/or modify it under the terms of either:

a)     the GNU General Public License
       <https://www.gnu.org/licenses/gpl-1.0.html> as published by the
       Free Software Foundation <http://www.fsf.org/>; either version 1
       <https://www.gnu.org/licenses/gpl-1.0.html>, or any later version
       <https://www.gnu.org/licenses/license-list.html#GNUGPL>, or
b)     the Artistic License 2.0
       <https://opensource.org/licenses/Artistic-2.0>,

subject to the following additional term: No trademark rights to "Paranoid" have been or are conveyed under any of the above licenses. However, "Paranoid" may be used fairly to describe this unmodified software, in good faith, but not as a trademark.

(c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com)

so yeah, two licenses, pick your fighter, but read the trademark clause before you go using "Paranoid" like you own it, bestie πŸ’…

okay that's the whole page, we ate, no cap. this was served up by perl v5.38.2, dated 2024-03-07 β€” and that's the ✨ main character energy ✨ of Parano...k::IPv6(3pm). bye pookie 🫢🌸

πŸ“¦ where this page comes from