The package contains various network utilities useful for:
- Getting info about IP address
- Checking if IP is in a certain range
- Expanding IP v6
- Converiting IP to bits representation
use Yiisoft\NetworkUtilities\IpHelper;
// checking IP version
$version = IpHelper::getIpVersion('192.168.1.1');
if ($version === IpHelper::IPV4) {
// ...
}
// checking if IP is in a certain range
if (!IpHelper::inRange('192.168.1.21/32', '192.168.1.0/24')) {
throw new \RuntimeException('Access denied!');
}
// expanding IP v6
echo IpHelper::expandIPv6('2001:db8::1');
// converting IP to bits representation
echo IpHelper::ip2bin('192.168.1.1');
// gets bits from CIDR Notation
echo IpHelper::getCidrBits('192.168.1.21/32');
use Yiisoft\NetworkUtilities\DnsHelper;
// checking DNS record availability
if(!DnsHelper::checkA('yiiframework.com')) {
// record not found
}