Net::Address::IPv4 - Moose Object for IPv4 Addresses
use Net::Address::IPv4; # We try stay pretty loose on what we'll take in for object creation, so my $ip = new Net::Address::IPv4 ( ip => "172.16.1.1", netmask => "255.255.255.0" ); # is the same as my $ip = new Net::Address::IPv4 ( ip =>"10101100000100000000001001100001", netmask => "24" ); # As you see, the dot-quad, cidr, and binary notation are all valid ways to # create a new instance. Internally, we store it all as the 32bit binary # because it's the lowest common denominator for ip addresses. print "My ip address is " . $ip->ip() . "\n"; # Prints the binary print "My ip address is " . $ip->ip4() . "\n"; # Prints the dot-quad print "My netmask is " . $ip->netmask() . "\n"; # Prints the binary print "My netmask is " . $ip->netmask4() . "\n"; # Prints the dot-quad print "My cidr is " . $ip->cidr() . "\n"; # Print the cidr mask # And we can even easily get the inverse mask print "Inverse netmask is " . $ip->netmask4_inv() . "\n"; # dot-quad inverse # What is the next or previous ip address in the block. my $next_ip = $ip->next_ip(); print "The next ip address is " . $next_ip->ip4() . "\n" if $next_ip; my $prev_ip = $ip->previous_ip(); print "The previous ip address is " . $prev_ip->ip4() . "\n" if $prev_ip; --OR-- print "The next ip address is " . $ip->next_ip->ip4() . "\n"; # next_ip() will return false if you are currently at the last ip address in # the objects block. i.e if your ip is 172.16.0.254/24, calling next_ip() # will return false, because 172.16.0.255 is the broadcast address and not # a valid ip address. This is also the same behaviour of previous_ip() # The caveat here is if the CIDR is /31 or /32, since those don't strictly # adhear to the concept of network and broadcast address's ## We can easily see the network and broadcast address in our specified range print "Broadcast Address: " . $ip->broadcast() . "\n"; ## Prints the binary print "Broadcast Address: " . $ip->broadcast4() . "\n"; # Prints the dot-quad print "Network Address: " . $ip->network() . "\n"; ## Prints the binary print "Network Address: " . $ip->network4() . "\n"; # Prints the dot-quad # We also have some pretty generic true-false tests to determine more info # about our IP address $self->is_class_d(); # 224.0.0.0/4 $self->is_class_e(); # 240.0.0.0/4 $self->is_linklocal(); # 169.254.0.0/16 $self->is_localhost(); # 127.0.0.0/8 $self->is_reserved(); # See RFC3330; 128.0.0.0/16, 191.255.0.0/16, # 192.0.0.0/24, 223.255.255.0/24 $self->is_rfc1918(); # 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 $self->is_rfc2544(); # 198.18.0.0/15 $self->is_testnet(); # 192.0.2.0/24
Provides an object for an IPv4 address.
Kyle Hultman, <khultman@gmail.com<gt>
Copyright 2009 the above AUTHORS
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =iten
To install Net::Address::IPv4, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Address::IPv4
CPAN shell
perl -MCPAN -e shell install Net::Address::IPv4
For more information on module installation, please visit the detailed CPAN module installation guide.