Calculates network information based on an IP address and netmask.
Fully populates the object properties based on the IP address and netmask/bitmask properties. Once these two fields are populated, calculate() will perform calculations to determine the network and broadcast address of the network.
bool check_ip(
string
$ip)
|
|
Validate the syntax of the given IP address (compatibility)
This function is identical to Net_IPv4::validateIP(). It is included merely for compatibility reasons.
Parameters:
bool ipInNetwork(
string
$ip, string
$network)
|
|
Determines whether or not the supplied IP is within the supplied network.
This function determines whether an IP address is within a network. The IP address ($ip) must be supplied in dot-quad format, and the network ($network) may be either a string containing a CIDR formatted network definition, or a Net_IPv4 object.
Parameters:
object true parseAddress(
$address, string
$ip)
|
|
Parse a formatted IP address
Given a network qualified IP address, attempt to parse out the parts and calculate qualities of the address.
The following formats are possible:
[dot quad ip]/[ bitmask ] [dot quad ip]/[ dot quad netmask ] [dot quad ip]/[ hex string netmask ]
The first would be [IP Address]/[BitMask]: 192.168.0.0/16
The second would be [IP Address] [Subnet Mask in dot quad notation]: 192.168.0.0/255.255.0.0
The third would be [IP Address] [Subnet Mask as Hex string] 192.168.0.0/ffff0000
Usage:
$cidr = '192.168.0.50/16'; $net = Net_IPv4::parseAddress($cidr); echo $net->network; // 192.168.0.0 echo $net->ip; // 192.168.0.50 echo $net->broadcast; // 192.168.255.255 echo $net->bitmask; // 16 echo $net->long; // 3232235520 (long/double version of 192.168.0.50) echo $net->netmask; // 255.255.0.0
Parameters:
bool validateIP(
string
$ip)
|
|
Validate the syntax of the given IP adress
Using the PHP long2ip() and ip2long() functions, convert the IP address from a string to a long and back. If the original still matches the converted IP address, it's a valid address. This function does not allow for IP addresses to be formatted as long integers.
Parameters:
bool validateNetmask(
string
$netmask)
|
|
Validate the syntax of a four octet netmask
There are 33 valid netmask values. This function will compare the string passed as $netmask to the predefined 33 values and return true or false. This is most likely much faster than performing the calculation to determine the validity of the netmask.
Parameters: