<? PHP/*** @ Author: Xiaoqing. huo * @ Date: 2012-12-05 * @ Param: $ IP ==> IPv4 address, $ netbit ==> mask bits */class ipconfigure {private $ IP; private $ netbit; public Function _ construct ($ IP, $ netbit) {$ this-> IP = $ IP; If (! ($ Netbit> = 0 & $ netbit <= 32) {$ this-> netbit = 32 ;}$ this-> netbit = $ netbit ;} // obtain the network number public function getsubnet () {return (long2ip (ip2long ($ this-> ip )) & (ip2long ($ this-> getmask ();} // obtain the IP address public function getip () {return $ this-> IP ;} // obtain the public function getnetbit () {return $ this-> netbit;} // obtain the public function getmask () {$ maskbinstr = str_repeat ("1 ", $ this-> netbit ). str_repeat ("0", 32-$ this-> netbit ); $ Masklong = bindec ($ maskbinstr); Return long2ip ($ masklong);} // gets the available network segment and returns the public function getiprange () of the start and end IP addresses () {$ maskbinstr = str_repeat ("1", $ this-> netbit ). str_repeat ("0", 32-$ this-> netbit); // net mask binary string $ inversemaskbinstr = str_repeat ("0", $ this-> netbit ). str_repeat ("1", 32-$ this-> netbit); // inverse mask $ iplong = ip2long ($ this-> ip); $ ipmasklong = bindec ($ maskbinstr ); $ inversei Pmasklong = bindec ($ inversemaskbinstr); $ network = $ iplong & $ ipmasklong; $ start = $ Network + 1; // remove the network number, host address $ end = ($ Network | $ inverseipmasklong)-1; // remove the broadcast address, return array (long2ip ($ start), long2ip ($ end);} // obtain the broadcast address public function broadcast () {return (long2ip (ip2long ($ this-> getsubnet () | (~ (Ip2long ($ this-> getmask () ;}}$ configure = new ipconfigure ("10.31.144.0", 22); echo "network number :", $ configure-> getsubnet (). php_eol; echo "<PRE>"; echo "available network segment:"; print_r ($ configure-> getiprange (); echo "subnet mask :", $ configure-> getmask (). php_eol; echo "broadcast address:", $ configure-> broadcast (). php_eol;