|
NAMENet::IPAddress - Functions used to manipulate IP addresses, masks and FQDN's.SYNOPSISuse Net::IPAddress;@ISA = qw(Net::IPAddress); DESCRIPTION"Net::IPAddr" is a collection of helpful functions used to convert IP addresses to/from 32-bit integers, applying subnet masks to IP addresses, validating IP address strings, and splitting a FQDN into its host and domain parts.No rocket science here, but I have found these functions to very, very handy. For example, have you ever tried to sort a list of IP addresses only to find out that they don't sort the way you expected? Here is the solution! If you convert the IP addresses to 32-bit integer addresses, they will sort in correct order.
"$subnet = mask("10.96.3.2",16);"
# $subnet = "10.96.0.0"
"$subnet = mask("10.21.4.22","255.240.0.0");" # $subnet = "10.16.0.0" "$subnet = mask(167837953,"255.255.255.0");" # $subnet = 167837952> This function, when used with the others, is very useful for computing IP addresses. For example, you need to add another server to a subnet that an existing server is on. You want the new server to be the ".17" address of a /24 subnet. This is done easily in the following example: "use Net::IPAddress"
"$server = "10.8.9.12";" "$newserver = num2ip(ip2num(mask($server,24)) + 17);" "print "New server IP is $newserver\n";" "New server IP is 10.8.9.17" The following code does exactly the same thing: "use Net::IPAddress;" "$server = "10.8.9.12";" "$newserver = num2ip(mask(ip2num($server),24) + 17);" "print "New server IP is $newserver\n";"
EXPORTS"Net::IPAddress" exports five functions "ip2num", "num2ip", "validaddr", "mask", and "fqdn".AUTHORScott Renner <srenner@mandtbank.com>, <srenner@comcast.net>COPYRIGHTCopyright(c) 2003-2005 Scott Renner. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |