hiqdev / php-ip-tools
A library based on rlanvin/php-ip for IP addresses calculations
Installs: 5 338
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- rlanvin/php-ip: ^3.0.0
- symfony/polyfill-php80: ^v1.25
Requires (Dev)
- infection/infection: ^0.25.5
- phpunit/phpunit: ^9.5
- roave/infection-static-analysis-plugin: ^1.13
- vimeo/psalm: ^4.22
This package is auto-updated.
Last update: 2024-11-30 02:05:19 UTC
README
This library provides tooling for IP address calculations based on rlanvin/php-ip
Free IP blocks calculation
Compute the best possible aligned IP blocks within a given range, excluding the taken blocks or IP addresses.
Example:
$block = '192.168.0.0/24'; $taken = ['192.168.0.64/28']; $calculator = new IpBlocksCalculator(); $free = $calculator->__invoke($block, $taken); var_dump($free); /* * [ * '192.168.0.0/26', * '192.168.0.80/28', * '192.168.0.96/27', * '192.168.0.128/25', * ] */
See more examples in IpBlocksCalculatorTest.
IP ranges parsing
Parse fuzzy IP address block definitions and unwrap it to an array:
Example:
IpRangeParser::fromString('192.0.2.[1,2,100-250]/24'); // ['192.0.2.1/24', '192.0.2.2/24', '192.0.2.100/24' ... '192.0.2.250/24']
See more examples in IpRangeParserTest.