NAME
Mnet::IP - Parse ipv4 and ipv6 addresses
SYNOPSIS
# refer to Mnet::IP::parse for all valid address input formats
$address = "127.0.0.1"
$address = "127.0.0.1/32"
$address = "127.0.0.1/255.255.255.255"
$address = "::1"
$address = "::1/128"
$address = "::127.0.0.1/96"
$address = "/32"
$address = "/255.255.255.255"
# return sting of binary digits for input ipv4 or ipv6 address
$binary = Mnet::IP::binary($address)
# return cidr from input address, /mask is converted
$cidr = Mnet::IP::cidr($address)
# return ipv4 or ipv6 portion of address, removing any /cidr or /mask
$ip = Mnet::IP::ip($address)
# return ipv4 portion of input address, removing any /cidr or /mask
$ipv4 = Mnet::IP::ipv4($address)
# return ipv6 portion of input address, removing any /cidr
$ipv6 = Mnet::IP::ipv6($address)
# return mask from input address, /cidr is converted
$mask = Mnet::IP::mask($address)
# return network ip/cidr for input address
$network = Mnet::IP::network($address)
# return ipv4, ipv6, cidr and mask values for input address
($ipv4, $ipv6, $cidr, $mask) = Mnet::IP::parse($address)
# return wildcard mask for /mask or /cidr of input address
$wildcard = Mnet::IP::wildcard($address)
DESCRIPTION
The following terms are used in this module:
address ipv4 or ipv6 address, see below
cidr count of network bits, such as 32 for an ipv4 host
ip ipv4 or ipv6 address
ipv4 ipv4 address, see below
ipv6 ipv6 address, see below
network network ip/cidr, such as 192.168.1.0/24
mask ipv4 dotted decimal mask, such as 255.255.255.0
wildcard ipv4 acl wildcard mask, such as 0.0.0.255
Refer to the parse function below for examples of valid address values.
The Socket::inet_pton function used in this module requires perl 5.12 or newer.
$binary = Mnet::IP::binary($address)
Return binary string of zeros and ones for a valid input ipv4 or ipv6 address, or undefined.
$cidr = Mnet::IP::cidr($address)
Return cidr from a valid input address containing a /cidr or /mask, or undefined if no /cidr or /mask was specified.
$boolean = Mnet::IP::ip($address)
Return ipv4 or ipv6 portion from a valid input address, or undefined.
$ipv4 = Mnet::IP::v4($address)
Return ipv4 portion from a valid input the address, or undefined.
$boolean = Mnet::IP::v6($address)
Return ipv6 fportion from a valid input address, or undefined.
$mask = Mnet::IP::mask($address)
Return dotted decimal mask from a valid input ipv4 address containing a /cidr or /mask, or undefined.
$network = Mnet::IP::network($address)
Return ipv4/cidr or ipv6/cidr network address from a valid input ipv4/cidr, ipv4/mask, or ipv6/cidr address, or undefined.
($ipv4, $ipv6, $cidr, $mask) = Mnet::IP::parse($address)
Parse input address and return separate ipv4, ipv6, cidr and mask values.
The following are examples of valid ipv4 addresses:
127.0.0.1
127.0.0.1/32
127.0.0.1/255.255.255.255
The following are examples of valid ipv6 addresses:
::1
::1/128
The following are examples of valid ipv6 addresses having embedded dotted decimal text ipv4 addresses, as per rfc 6502 section 2:
::127.0.0.1
::127.0.0.1/96
The following are examples of valid /cidr and /mask values by themselves:
/32
/255.255.255.255
All output values are undefined if there were any errors.
$wildcard = Mnet::IP::wildcard($mask)
Return dotted decimal wildcard mask for a valid input ipv4 address contianing a /cidr or /mask, , or undefined.