Net_IPv4::calculate() – Calculates network information based on an IP address and netmask.


require_once 'Net/IPv4.php';

mixed calculate ( )


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.


Calculating broadcast and network address


require 'Net/IPv4.php';

// create IPv4 object
$ip_calc = new Net_IPv4();

// set variables
$ip_calc->ip "";
$ip_calc->netmask "";

/* alternative method with numerical values:
$ip_calc->long = 3232235786;
$ip_calc->bitmask = 24;

// calculate
$error $ip_calc->calculate();
if (!
// if returned true, output
echo "Your network address: ".$ip_calc->network."<br />";
"Your broadcast address: ".$ip_calc->broadcast."<br />";
// otherwise handle error
echo "An error occured: ".$error->getMessage();


Return value

boolean - Returns TRUE on success, PEAR_Error on failure.


This function can not be called statically.

Parse a CIDR address (address/netmask combination). (Previous) Determines whether or not the supplied IP is within the supplied network. (Next)
Last updated: Wed, 18 Jan 2017 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.