IPV4CALC(1) User Contributed Perl Documentation IPV4CALC(1)NAME
ipv4calc - Calculates IPv4 elements from an address.
SYNOPSIS
ipv4calc [ --network | --broadcast | --netmask |
--address | --cidr ] addr
DESCRIPTION
If an option is specified ipv4calc calculates the requested element from the address and prints it on stdout.
If multiple options are specified, only the first one is printed.
If no options are specified, the program prints the host part of the address, the network and the broadcast address as deduced from the
given address.
If address doesn't contains a netmask or mask length, the default one is assumed.
AUTHOR
Francis J. Lacoste <francis.lacoste@iNsu.COM>
COPYRIGHT
Copyright (c) 1999,2000 iNsu Innovations Inc. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms as perl itself.
SEE ALSO Network::IPv4Addr(3).
perl v5.12.1 2000-08-01 IPV4CALC(1)
Check Out this Related Man Page
Paranoid::Network::IPv4(3pm) User Contributed Perl Documentation Paranoid::Network::IPv4(3pm)NAME
Paranoid::Network::IPv4 - IPv4-related functions
VERSION
$Id: IPv4.pm,v 0.1 2012/05/29 21:37:44 acorliss Exp $
SYNOPSIS
use Paranoid::Network::IPv4;
@net = ipv4NetConvert($netAddr);
$rv = ipv4NetIntersect($net1, $net2);
or
use Paranoid::Network::IPv4 qw(:all);
print "Valid IP address
" if $netAddr =~ /^@{[ IPV4REGEX ]}$/;
@net = ipv4NetConvert($netAddr);
$broadcast = $net[IPV4BRDCST];
DESCRIPTION
This module contains a few convenience functions for working with IPv4 addresses.
By default only the subroutines themselves are imported. Requesting :all will also import the constants as well.
SUBROUTINES /METHODS
ipv4NetConvert
@net = ipv4NetConvert($netAddr);
This function takes an IPv4 network address in string format and converts it into an array containing the base network address, the
broadcast address, and the netmask, in integer format. The network address can have the netmask in either CIDR format or dotted quads.
In the case of a single IP address, the array with only have one element, that of the IP in integer format.
Passing any argument to this function that is not a string representation of an IP address (including undef values) will cause this
function to return an empty array.
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 the true
value can vary to indicate which 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
The function handles the same string formats as ipv4NetConvert, but will allow you to test single IPs in integer format as well.
CONSTANTS
These are only imported if explicity requested or with the :all tag.
MAXIPV4CIDR
Simply put: 32. This is the largest CIDR notation supported in IPv4.
IPV4REGEX
Regular expression: qr/(?:d{1,3}.){3}d{1,3}/sm
You can use this for validating IP addresses as such:
$ip =~ m#^@{[ IPV4REGEX ]}$#;
or to extract potential IPs from extraneous text:
(@ips) = ( $string =~ m#(@{[ IPV4REGEX ]})#gsm);
IPV4CIDRRGX
Regular expression:
qr#(@{[ IPV4REGEX ]})(?:/(d+|@{[ IPV4REGEX ]}))?#sm
By default this will extract an IP or CIDR notation network address:
($net, $mask) = ( $ip =~ m#^@{[ IPV4CIDRRGX ]}$# );
In the case of a simple IP address $mask will be undefined.
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
o Paranoid
o Paranoid::Network::Socket
BUGS AND LIMITATIONS AUTHOR
Arthur Corliss (corliss@digitalmages.com)
LICENSE AND COPYRIGHT
This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information.
(c) 2012, Arthur Corliss (corliss@digitalmages.com)
perl v5.14.2 2012-05-29 Paranoid::Network::IPv4(3pm)