Net::Works::Address - An object representing a single IP (4 or 6) address
version 0.08
my $ip = Net::Works::Address->new_from_string( string => '1.2.3.4' ); print $ip->as_string(); # 1.2.3.4 print $ip->as_integer(); # 16909060 print $ip->as_binary(); # 4-byte packed form of the address print $ip->as_bit_string(); # 00000001000000100000001100000100 print $ip->version(); # 4 print $ip->mask_length(); # 32 my $next = $ip->next_ip(); # 1.2.3.5 my $prev = $ip->previous_ip(); # 1.2.3.4 if ( $next > $ip ) { ... } my @sorted = sort $next, $prev, $ip; my $ip = Net::Works::Address->new_from_string( string => 'a900::1234' ); print $ip->as_integer(); # 224639531287650782520743393187378238004 my $ip = Net::Works::Address->new_from_integer( integer => 16909060 );
Objects of this class represent a single IP address. It can handle both IPv4 and IPv6 addresses. It provides various methods for getting information about the address, and also overloads the objects so that addresses can be compared as integers.
For IPv6, it uses 128-bit integers (via Math::Int128) to represent the numeric value of an address.
This class provides the following methods:
This method takes a string parameter and an optional version parameter. The string parameter should be a string representation of an IP address.
string
version
The version parameter should be either 4 or 6, but you don't really need this unless you're trying to force a dotted quad to be interpreted as an IPv6 address or to a force an IPv6 address colon-separated hex number to be interpreted as an IPv4 address.
4
6
This method takes a integer parameter and an optional version parameter. The integer parameter should be an integer representation of an IP address.
integer
The version parameter should be either 4 or 6. Unlike with strings, you'll need to set the version explicitly to get an IPv6 address.
Returns a string representation of the address in the same format as inet_ntop, e.g., "1.2.3.4", "::1.2.3.4", or "ffff::a:1234".
Returns the address as an integer. For IPv6 addresses, this is returned as a Math::Int128 object, regardless of the value.
Returns the packed binary form of the address (4 or 16 bytes).
Returns the address as a string of 1's and 0's, like "00000000000000000000000000010000".
This returns a dotted quad representation of an address, even if it's an IPv6 address. However, this will die if the address is greater than the max value of an IPv4 address (2**32 - 1). It's primarily useful for debugging.
Returns a 4 or 6 to indicate whether this is an IPv4 or IPv6 address.
Returns the mask length for the IP address, which is either 32 (IPv4) or 128 (IPv6).
An alias for $ip->mask_length(). This helps make addresses & network objects interchangeable in some cases.
$ip->mask_length()
Returns the numerically next IP, regardless of whether or not it's in the same subnet as the current IP.
This will throw an error if the current IP address it the last address in its IP range.
Returns the numerically previous IP, regardless of whether or not it's in the same subnet as the current IP.
This will throw an error if the current IP address it the first address in its IP range (address 0).
This class overloads numeric comparison, allowing you to compare two objects numerically and to sort them.
It also overloads stringification to call the $ip->as_string() method.
$ip->as_string()
Dave Rolsky <autarch@urth.org>
Olaf Alders <olaf@wundercounter.com>
Greg Oschwald <oschwald@cpan.org>
This software is Copyright (c) 2013 by MaxMind, Inc..
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Net::Works, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Works
CPAN shell
perl -MCPAN -e shell install Net::Works
For more information on module installation, please visit the detailed CPAN module installation guide.