Example of converting an IP address to a broadcast address in php

Source: Internet
Author: User
BroadcastAddress (broadcast address) is an address used to send messages to all workstations in the network at the same time. In a network that uses the TCPIP protocol, the IP address of the host ID segment hostID of all 1 is the broadcast address, broadcast... broadcast Address (Broadcast Address) is an Address used to send messages to all workstations in the network at the same time. In a network using the TCP/IP protocol, the IP address of host ID 1 in the host identification segment is the broadcast address, and the Broadcast Group is sent to all computers involved in the host ID segment.

Network broadcast address calculation method:

(1) perform "bit and" operations on the IP address and subnet mask to obtain the network address

(2) calculate the subnet mask "" and perform "bit or" operations with the network address to obtain the broadcast address.

 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 ;}


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.