Componette

Componette

mesour

mesour / ip-addresses v0.3.0

Ip address validation and normalization (IPv4 and IPv6)

download-cloud-line composer require mesour/ip-addresses

Mesour IP addresses

  • Author

  • IP address normalizer and validator. For IPv4 and IPv6.

Install

  • With Composer

      composer require mesour/ip-addresses
    
  • Or download source from GitHub

Usage

Usage: Mesour\IpAddresses\IpAddressValidator

Assert::true(IpAddressValidator::isIpV6('2a00:5565:2222:800::200e'));

Assert::true(IpAddressValidator::isIpV4('127.0.0.1'));

Usage: Mesour\IpAddresses\IpAddressNormalizer

Normalize IPv6:

IpAddressNormalizer::normalizeIpV6('2001:db8:800::ff00:42:8329');

// result is: 2001:0db8:0800:0000:0000:ff00:0042:8329

Compress IPv6:

IpAddressNormalizer::compressIpV6('2001:0db8:0800:0000:0000:ff00:0042:8329');

// result is: 2001:db8:800::ff00:42:8329

Usage: Mesour\IpAddresses\IpAddress

Normalize IPv4:

$ipAddress = IpAddress::create('127.0.0.1');

$ipAddress->isIpV4(); // result is: true
$ipAddress->isIpV6(); // result is: false
$ipAddress->getValue(); // result is: 127.0.0.1

Normalize IPv6:

  • Result of getValue is compressed IPv6 value
$ipAddress = IpAddress::create('2001:0db8:0800:0000:0000:ff00:0042:8329');

$ipAddress->isIpV4(); // result is: false
$ipAddress->isIpV6(); // result is: true
$ipAddress->getValue(); // result is: 2001:db8:800::ff00:42:8329

Development

  • Syntax check: vendor/bin/parallel-lint src tests
  • PHP Stan: vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests
  • Run tests: vendor/bin/tester -p php tests/ -s -c tests/php.ini
  • v0.3.0 Released version 0.3.0

    Changes

    • Fixed for PHP 8 and 8.1
    • Increased minimum compatibility to PHP 8+
    • Added IpAddress value object
  • v0.2.0 Released version 0.2.0

    Changes

    • Fixed for PHP 7.4
    • Increased minimum compatibility to PHP 7.1+
  • v0.1.0 Released version 0.1.0

    initial

price-tag-2-line

Badges

guide-fill

Dependencies

php (>=8.0)
Componette Componette felix@nette.org