public function testContains() { $subnet = IPv4Subnet::fromCidr(new IPv4Address("192.168.3.1"), 24); $this->assertFalse($subnet->contains(new IPv4Address("192.168.2.255"))); $this->assertTrue($subnet->contains(new IPv4Address("192.168.3.0"))); $this->assertTrue($subnet->contains(new IPv4Address("192.168.3.255"))); $this->assertFalse($subnet->contains(new IPv4Address("192.168.4.0"))); }
/** * Returns whether the address is part of the private address pool (RFC 1918) * * @return bool */ public function isPrivate() { /** @var $subnets Subnet[] */ $subnets = array(Subnet::fromCidr(new Address("10.0.0.0"), 8), Subnet::fromCidr(new Address("172.16.0.0"), 12), Subnet::fromCidr(new Address("192.168.0.0"), 16)); foreach ($subnets as $subnet) { if ($subnet->contains($this)) { return true; } } return false; }