search.cpan.org/dist/Net-IP/IP.pm
DESCRIPTION ^ This module provides functions to deal with IPv4/IPv6 addresses. The module can be used as a class, allowing the user to instantiate IP objects, which can be single IP addresses, prefixes, or ranges of addresses. There is also a procedural way of accessing most of the functions. Most subroutines can take either IPv4 or IPv6 addresses transparently.
The new() function accepts IPv4 and IPv6 addresses: $ip = new Net::IP ('dead:beef::/32') || die ... Optionnaly, the function can be passed the version of the IP. Otherwise, it tries to guess what the version is (see _is_ipv4() and _is_ipv6.
OBJECT METHODS ^ Most of these methods are front-ends for the real functions, which use a procedural interface. Most functions return undef on failure, and a true value on success. A detailed description of the procedural interface is provided below.
This method has the same functionality as the new() method, except that it reuses an existing object to store the new IP. It returns an IP object on success, and undef on failure.
The error number is set whenever one of the methods produces an error. Also, a global $ERRNO variable is set when an error is produced.
aggregate Aggregate 2 IPs - Append one range/prefix of IPs to another. The last address of the first range must be the one immediately preceding the first address of the second range.
PROCEDURAL INTERFACE ^ These functions do the real work in the module. Like the OO methods, most of these return undef on failure. In order to access error codes and strings, instead of using $ip->error() and $ip->errno(), use the global functions Error() and Errno(). The functions of the procedural interface are not exported by default. In order to import these functions, you need to modify the use statement for the module: use Net::IP qw(:PROC);
Error Returns the error string corresponding to the last error generated in the module. This is also useful for the OO interface, as if the new() function fails, we cannot call $ip->error() and so we have to use Error().
ip_bintoip Transform a bit string into an IP address Params : binary IP, IP version Returns : IP address on success, undef otherwise $ip = ip_bintoip ($binip,6);
This is necessary because Math::BigInt is not compliant. Params : BigInt, IP version Returns : binary IP $binip = ip_inttobin ($bigint);
ip_is_ipv4 Check if an IP address is of type 4 Params : IP address Returns : 1 (yes) or 0 (no) ip_is_ipv4($ip) and print "$ip is IPv4";
ip_is_ipv6 Check if an IP address is of type 6 Params : IP address Returns : 1 (yes) or 0 (no) ip_is_ipv6($ip) and print "$ip is IPv6";
ip_expand_address Expand an IP address from compact notation. Params : IP address, IP version Returns : expanded IP address or undef on failure $ip = ip_expand_address ($ip,4);
ip_last_address_bin Return the last binary address of a prefix. Params : First binary IP, prefix length, IP version Returns : Binary IP $lastbin = ip_last_address_bin ($ip,$len,6);
ip_get_prefix_length Get the prefix length for a given range of 2 IPs. Params : First binary IP, Last binary IP Returns : Length of prefix or undef (problem) $len = ip_get_prefix_length ($ip1,$ip2);
Params : Four binary IPs (begin of range 1,end1,begin2,end2), IP version $IP_PARTIAL_OVERLAP (ranges overlap) $IP_NO_OVERLAP (no overlap) $IP_A_IN_B_OVERLAP (range2 contains range1) $IP_B_IN_A_OVERLAP (range1 contains range2) $IP_IDENTICAL (ranges are identical) undef (problem) (ip_is_overlap($rb1,$re1,$rb2,$re2,4) eq $IP_A_IN_B_OVERLAP) and do {};
ip_get_embedded_ipv4 Get an IPv4 embedded in an IPv6 address Params : IPv6 Returns : IPv4 string or undef (not found) $ip4 = ip_get_embedded($ip6);
ip_aggregate Aggregate 2 ranges of binary IPs Params : 1st range (1st IP, Last IP), last range (1st IP, last IP), IP version Returns : prefix or undef (invalid) $prefix = ip_aggregate ($bip1,$eip1,$bip2,$eip2) || die ...
ip_iptype Return the type of an IP (Public, Private, Reserved) Params : IP to test, IP version Returns : type or undef (invalid) $type = ip_iptype ($ip);
ip_check_prefix Check the validity of a prefix Params : binary IP, length of prefix, IP version Returns : 1 or undef (invalid) Checks if the variant part of a prefix only has 0s, and the length is correct.
ip_reverse Get a reverse name from a prefix Params : IP, length of prefix, IP version Returns : Reverse name or undef (error) $reverse = ip_reverse ($ip);
ip_normalize Normalize data to a range/prefix of IP addresses Params : Data String (Single IP, Range, Prefix) Returns : ip1, ip2 (if range/prefix) or undef (error) ($ip1,$ip2) = ip_normalize ($data);
ip_auth Return IP authority information from the IP::Authority module Params : IP, version Returns : Auth info (RI for RIPE, AR for ARIN, etc) $auth = ip_auth ($ip,4);
|