public static function fromString($string) { $string = trim($string); try { return IPv4\Range::fromString($string); } catch (InvalidFormatException $e) { } try { return IPv4\Subnet::fromString($string); } catch (InvalidFormatException $e) { } try { return new IPv4\Address($string); } catch (InvalidFormatException $e) { } throw new InvalidFormatException("Unknown address format"); }
public function subnetMatch() { return array(array(IPv4Subnet::fromString("10.0.0.0/8"), new IPv4Address("10.23.54.255"), true), array(IPv4Subnet::fromString("10.0.0.0/8"), new IPv4Address("10.0.0.0"), true), array(IPv4Subnet::fromString("10.0.0.0/8"), new IPv4Address("10.255.255.255"), true), array(IPv4Subnet::fromString("10.0.0.0/8"), new IPv4Address("11.0.0.0"), false), array(IPv4Subnet::fromString("10.0.0.0/8"), new IPv4Address("9.255.255.255"), false), array(IPv4Subnet::fromString("10.0.0.0/8"), "10.0.2.3", false)); }
/** * 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; }