Translate

Archives

Using Perl Net::IP to Manipulate IPv4 Addresses

In a previous post, I demonstrated a Korn shell script which determined the subnet mask for a range of IPv4 addresses. Perl has a module called Net::IP which provides a number of functions which can be used to manipulate IPv4 (and also IPv6) addresses to provide the same information and a lot more besides. For example, the following code outputs a lot of information about a classless prefix: use Net::IP; my $ip = new Net::IP (‘10.1.1.0/24’) or die (Net::IP::Error()); print ("IP : ".$ip->ip()."n"); print ("Sho : ".$ip->short()."n"); print ("Bin : ".$ip->binip()."n"); print ("Int : ".$ip->intip()."n"); print ("Mask: ".$ip->mask()."n"); print ("Last: