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

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

πŸ’– Paranoid::Network::IPv4 β€” the manual page, but make it cute πŸ’–

okay bestie, so this is the manual page for Paranoid::Network::IPv4, which lives in the Perl world as Parano...k::IPv4(3pm) (that's the abbreviated name, she's shy). It's part of the User Contributed Perl Documentation family, and it's lowkey just a little collection of helper functions for dealing with IPv4 addresses. Let's get into it. πŸ¦‹


✨ NAME ✨

Paranoid::Network::IPv4 β€” IPv4-related functions. that's it, that's the vibe. πŸ’…


πŸ“Œ VERSION πŸ“Œ

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

🌸 SYNOPSIS 🌸

here's how you actually use her:

use Paranoid::Network::IPv4;

@net = ipv4NetConvert($netAddr);
$rv = ipv4NetIntersect($net1, $net2);

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

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

@net = ipv4NetConvert($netAddr);
$broadcast = $net[IPV4BRDCST];

use Paranoid::Network::IPv4 qw(:ipv4Sort);

@nets = sort ipv4StrSort    @nets;
@nets = sort ipv4PackedSort @nets;
@nets = sort ipv4NumSort    @nets;

πŸ’œ DESCRIPTION πŸ’œ

this module contains a few convenience functions for working with IPv4 addresses. that's the whole pitch. she's a helper, not a whole personality. πŸŽ€


🧚 IMPORT LISTS 🧚

by default, this module exports these symbols, no questions asked, they just show up:

ipv4NetConvert ipv4NetIntersect

and these specialized import lists exist too, if you want to be specific about it:

List        Members
--------------------------------------------------------
base        @defaults
constants   MAXIPV4CIDR IPV4REGEX IPV4CIDRRGX IPV4BASE
            IPV4BRDCST IPV4MASK
ipv4Sort    ipv4NumSort ipv4StrSort ipv4PackedSort
all         @base @constants @ipv4sort

πŸ‘‘ SUBROUTINES/METHODS πŸ‘‘

ipv4NetConvert

@net = ipv4NetConvert($netAddr);

okay so this one takes an IPv4 network address as a string and converts it into an array holding the base network address, the broadcast address, and the netmask β€” all in integer format. ✨

the network address can carry its netmask in either CIDR format or dotted quads. both valid, both welcome. 🫢

if you hand her a single IP address, the array only has one element: that IP, in integer format. no extras, no padding.

and if you pass literally anything that isn't a string representation of an IP address β€” including undef values β€” this function returns an empty array. she's not mad, she's just not doing it. πŸ’€

ipv4NetIntersect

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

this function tests whether an IP or subnet intersects with another IP or subnet. the return value is essentially boolean, but here's the slay part: 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

she handles the same string formats as ipv4NetConvert, but she'll also let you test single IPs in integer format as well. flexible queen. πŸ’…


ipv4StrSort

@sorted = sort ipv4StrSort @nets;

this function lets IPv4 addresses and networks come through in string format. networks can be in CIDR format. sorts in ascending order. ⭐


ipv4PackedSort

@sorted = sort ipv4PackedSort @nets;

this one sorts IPv4 addresses as returned by inet_aton. sorts in ascending order. πŸ¦‹


ipv4NumSort

@sorted = sort ipv4NumSort @nets;

ngl this function is rather pointless, but she's included merely for completeness. the addresses are in unpacked, native integer format β€” the kind you get from this:

$ip = unpack 'N', inet_aton($ipAddr);

sorts in ascending order. we love a completionist. πŸ₯°


🌈 CONSTANTS 🌈

these are only imported if you explicitly request them or use the :all tag. no sneaky auto-imports here. no cap.


MAXIPV4CIDR

simply put: 32. this is the largest CIDR notation supported in IPv4. she's the ceiling, literally. πŸ”₯


IPV4REGEX

a regular expression.

you can use it to validate IP addresses like this:

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

or to extract potential IPs from extraneous text:

@ips = ( $string =~ m#(@{[ IPV4REGEX ]})#gsm);

IPV4CIDRRGX

a regular expression.

by default this will test a CIDR notation or dotted quad network address:

$netaddr =~ m#@{[ IPV4CIDRRGX ]}$#s;

or extract network addresses from a string:

@networks = ( $string =~ m#(@{[ IPV4CIDRRGX ]})#s );

IPV4BASE

this is the ordinal index of the base network address as returned by ipv4NetConvert. πŸ“


IPV4BRDCST

this is the ordinal index of the broadcast address as returned by ipv4NetConvert. πŸ“£


IPV4MASK

this is the ordinal index of the network mask as returned by ipv4NetConvert. 🎭


πŸ“ DEPENDENCIES πŸ“

she does not stand alone, she has a support system:

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

πŸ’€ BUGS AND LIMITATIONS πŸ’€

...nothing here. literally empty. no known bugs, no limitations listed, which is either iconic or suspicious and honestly it's giving both. πŸ“­βœ¨


🌟 AUTHOR 🌟

Arthur Corliss (corliss@digitalmages.com) β€” the genius behind the whole thing, we stan. πŸ‘‘


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

  1. 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
  2. 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)


okay and for the sign-off, bestie: this page comes to you as Parano...k::IPv4(3pm) from perl v5.38.2, dated 2024-03-07. that's the whole energy. go forth and intersect some subnets. slay. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from