Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.93 KB

README.md

File metadata and controls

59 lines (45 loc) · 1.93 KB

Yii network utilities


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

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage

General usage

IpHelper

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');

DnsHelper

use Yiisoft\NetworkUtilities\DnsHelper;

// checking DNS record availability
if(!DnsHelper::checkA('yiiframework.com')) {
  // record not found
}