Ejemplo n.º 1
0
 /**
  * Convert an IP address to a binary character string (i.e. "01111111000000000000000000000001")
  *
  * @param IPAddress $ip address object
  *
  * @return string
  */
 protected function asBinaryString(IPAddress $ip)
 {
     $length = 4 === $ip->ipVersion() ? 4 : 16;
     $binaryIp = $ip->asBinary();
     $bits = '';
     for ($i = 0; $i < $length; $i++) {
         $byte = decbin(ord($binaryIp[$i]));
         $bits .= substr("00000000" . $byte, -8);
     }
     return $bits;
 }