コード例 #1
0
 public function containsAddress($address)
 {
     $address = PhutilIPAddress::newAddress($address);
     $block_bits = $this->ip->toBits();
     $address_bits = $address->toBits();
     return strncmp($block_bits, $address_bits, $this->bits) === 0;
 }
コード例 #2
0
 public function testIPAddressToBits()
 {
     $cases = array('0.0.0.0' => '00000000000000000000000000000000', '255.255.255.255' => '11111111111111111111111111111111', '255.0.0.0' => '11111111000000000000000000000000', '0.0.0.1' => '00000000000000000000000000000001', '0.0.0.2' => '00000000000000000000000000000010', '0.0.0.3' => '00000000000000000000000000000011');
     foreach ($cases as $input => $expect) {
         $actual = PhutilIPAddress::newAddress($input)->toBits();
         $this->assertEqual($expect, $actual, 'PhutilIPAddress[' . $input . ']->toBits()');
     }
 }