Network broadcast address calculation method: (1) bitwise AND operation on the IP address and subnet mask to obtain the network address (2) "inverse" Operation on the subnet mask, then perform the bitwise OR operation with the network address to obtain the ip address of the broadcast address. Convert the ip address of the broadcast address privatefunctionip2broadcast ($ ip, $ mask) {$ ipSplitexplode (., $ ip); $ ma
Calculation Method of the network broadcast address: (1) bitwise and operation of the IP address and subnet mask to obtain the network address (2) "inverse" Operation of the subnet mask, then perform the bitwise OR operation with the network address to obtain the broadcast address // ip address translation broadcast address private function ip2broadcast ($ ip, $ mask) {$ ipSplit = explode ('. ', $ ip); $ ma
Network broadcast address calculation method:
(1) perform bitwise AND operations on the IP address and subnet mask to obtain the network address.
(2) Calculate the subnet mask "inverse", and then perform "bitwise OR" operation with the network address to obtain the broadcast address.
// Ip address translation broadcast address private function ip2broadcast ($ ip, $ mask) {$ ipSplit = explode ('. ', $ ip); $ maskSplit = explode ('. ', $ mask); $ broadcast = null; for ($ I = 0; $ I <4; $ I ++) {$ ipBin = sprintf ("% B ", $ ipSplit [$ I]); while (8-strlen ($ ipBin)> 0) $ ipBin = "0 ". $ ipBin; $ maskBin = sprintf ("% B", $ maskSplit [$ I]); while (8-strlen ($ maskBin)> 0) $ maskBin = "0 ". $ maskBin; $ broadcastBin = null; for ($ j = 0; $ j <8; $ j ++) {$ broadcastBin. = ( ! Intval (substr ($ maskBin, $ j, 1) | (intval (substr ($ ipBin, $ j, 1) & intval (substr ($ maskBin, $ j, 1);} if ($ I> 0) $ broadcast. = ". "; $ broadcast. = bindec ($ broadcastBin);} return $ broadcast ;}
Title: php converts IP addresses to broadcast addresses
Link to this article: http://www.maben.com.cn/archives/604.html.