The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::IP::Identifier::Net - subclass Net::IP to add some functionality

VERSION

version 0.111

SYNOPSIS

  use Net::IP::Identifier::Net;

  my $net = Net::IP::Identifier::Net->new( IP );

DESCRIPTION

Net::IP::Identifier::Net subclasses Net::IP. IP can be any of the forms accepted by Net::IP.

Stringification is provided, and uses the print method.

Methods

new( IP )

Creates a new Net::IP::Identifier::Net object. 'IP' can be a Net::IP or a Net::IP::Identifier::Net object, or it can be any of the string formats acceptable to Net::IP. If 'IP' is a Net::IP::Identifier::Net, it is immediately returned as the object. If 'IP' is a string, it is saved as the src_str. If 'IP' is a Net::IP object, the print method is called to create the src_str.

src_str( [ string ] )

The string that created the object.

int_to_ip( $int, [ 4 | 6 ] );

Converts an integer (or a Math::BigInt) to an IP (v4 or v6) address. If not defined, the version (second argument) is set to 4.

range_to_cidrs

If $net is a netblock, it may be specified by a range (like N.N.N.N - M.M.M.M) which may or may not be representable by a single CIDR (N.N.N.N/M). This method returns an array of Net::IP::Identifier::Net objects that span the original range. If $net is representable by a single CIDR, the returned array simply contains the original $net.

masklen

Similar to Net::IP->prefixlen, but always returns a value, unlike prefixlen. If the netblock doesn't span an even binary boundary, the return value represents a big enough range that the netblock fits in it.

masked_ip

Returns a string of 1's and 0's that are the starting IP address of $net masked with the inverse of the netmask. This means you get the upper significant bits (the bits that don't change within this netblock). The lower bits are removed.

print

Override of Net::IP->print, returns a string. For Net::IP::Identifier::Net objects which represent a single IP, the string is a dotted decimal quad (N.N.N.N). If $ip represents a netblock, the string is a CIDR (N.N.N.N/W) if possible, otherwise it is a range (N.N.N.N - N.N.N.N). IPv6 addresses are compressed when possible, but IPv4 are not.

Note that Net::IP->print adds '/32' to single IPs, and it compresses CIDRs if possible (like N.N/16).

This method is used for stringifying the object.

my $str = $net->compressed_ip

Returns a string. Calls the Net::IP::ip_compress_address() function.

AUTHOR

Reid Augustin <reid@hellosix.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Reid Augustin.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.