/network-utilities

Network related utilities

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

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

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