cmdrsharp / ip-addressing
A collection of traits for IP Operations.
1.2.0.0
2019-08-21 20:31 UTC
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2026-02-22 11:20:27 UTC
README
A collection of traits for general IP operations. New traits may be added over time.
Current Requirements
- PHP 7.1 or newer
Installation
Via composer
$ composer require cmdrsharp/ip-addressing
Usage
Use the applicable Trait in your classes.
use CmdrSharp\IpAddressing\IPv4; use CmdrSharp\IpAddressing\Subnet; class RandomClass { use IPv4, Subnet; protected function randomFunction() { $result = $this->getNetworkFromIp('192.168.0.55', '255.255.255.0'); // 192.168.0.0 $result = $this->getBroadcastFromIp('192.168.0.55', '255.255.255.0'); // 192.168.0.255 $result = $this->getCidrFromNetmask('255.255.255.0'); // 24 } }
What trait contains what?
IPv4
getNetworkFromIp(string $ip, string $netmask): stringgetBroadcastFromIp(string $ip, string $netmask): string
Subnet
getCidrFromNetmask(string $netmask): string
Versioning
This package follows Explicit Versioning.