Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

paranoid::network::ipv4(3pm) [debian 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)

Check Out this Related Man Page

Paranoid::Network(3pm)					User Contributed Perl Documentation				    Paranoid::Network(3pm)

NAME
Paranoid::Network - Network functions for paranoid programs VERSION
$Id: Network.pm,v 0.68 2012/05/29 21:38:19 acorliss Exp $ SYNOPSIS
use Paranoid::Network; $rv = ipInNetwork($ip, @networks); $rv = hostInDomain($host, @domains); @ips = extractIP($string1, $string2); $rv = netIntersect( $cidr1, $cidr2 ); DESCRIPTION
This modules contains functions that may be useful for network operations. IPv6 is supported out of the box starting with Perl 5.14. Earlier versions of Perl will require Socket6(3) installed as well. If it is available this module will use it automatically. SUBROUTINES
/METHODS ipInNetwork $rv = ipInNetwork($ip, @networks); This function checks the passed IP against each of the networks or IPs in the list and returns true if there's a match. The list of networks can be either individual IP address or network addresses in CIDR notation or with full netmasks: @networks = qw(127.0.0.1 192.168.0.0/24 172.16.12.0/255.255.240.0); IPv6 is supported if the Socket6(3) module is installed or you're running Perl 5.14 or higher. This routine will select the appropriate address family based on the IP you're testing and filter out the opposing address family in the list. NOTE: IPv4 addresses encoded as IPv6 addresses, e.g.: ::ffff:192.168.0.5 are supported, however an IP address submitted in this format as the IP to test for will be converted to a pure IPv4 address and compared only against the IPv4 networks. This is meant as a convenience to the developer supporting dual-stack systems to avoid having to list IPv4 networks in the array twice like so: ::ffff:192.168.0.0/120, 192.168.0.0/24 Just list IPv4 as IPv4, IPv6 as IPv6, and this routine will convert IPv6-encoded IPv4 addresses automatically. This would make the following test return a true value: ipInNetwork( '::ffff:192.168.0.5', '192.168.0.0/24' ); but ipInNetwork( '::ffff:192.168.0.5', '::ffff:192.168.0.0/120' ); return a false value. This may seem counter intuitive, but it simplifies things in (my alternate) reality. Please note that this automatic conversion only applies to the IP argument, not to any member of the network array. hostInDomain $rv = hostInDomain($host, @domains); This function checks the passed hostname (fully qualified) against each of the domains in the list and returns true if there's a match. None of the domains should have the preceding '.' (i.e., 'foo.com' rather than '.foo.com'). extractIPs @ips = extractIP($string1, $string2); This function extracts IP addresses from arbitrary text. If you have Socket6(3) installed or running Perl 5.14 or higher it will extract IPv6 addresses as well as IPv4 addresses. This extracts only IP addresses, not network addresses in CIDR or dotted octet notation. In the case of the latter the netmask will be extracted as an additional address. NOTE: in the interest of performance this function does only rough regex extraction of IP-looking candidates, then runs them through inet_aton (for IPv4) and inet_pton (for IPv6) to see if they successfully convert. Even with the overhead of Paranoid (with debugging and loadModule calls for Socket6 and what-not) it seems that this is an order of a magnitude faster than doing a pure regex extraction & validation of IPv6 addresses. NOTE: Like the ipInNetwork function we filter out IPv4 addresses encoded as IPv6 addresses since that address is already returned as a pure IPv4 address. netIntersect $rv = netIntersect( $cidr1, $cidr2 ); This function is an IPv4/IPv6 agnostic wrapper for the ipv{4,6}NetIntersect functions provided by Paranoid::Network::IPv{4,6} modules. The return value from which ever function called is passed on directly. Passing this function non-IP or undefined values simply returns a zero. DEPENDENCIES
o Paranoid o Paranoid::Network::Socket o Paranoid::Network::IPv4 o Paranoid::Network::IPv6 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) 2005, Arthur Corliss (corliss@digitalmages.com) perl v5.14.2 2012-05-29 Paranoid::Network(3pm)
Man Page