https://github.com/hiqdev/php-ip-tools
A library for IP addresses calculations
https://github.com/hiqdev/php-ip-tools
Last synced: 12 months ago
JSON representation
A library for IP addresses calculations
- Host: GitHub
- URL: https://github.com/hiqdev/php-ip-tools
- Owner: hiqdev
- Created: 2021-09-19T08:26:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-03T16:53:34.000Z (about 4 years ago)
- Last Synced: 2024-11-12T19:47:10.154Z (over 1 year ago)
- Language: PHP
- Size: 64.5 KB
- Stars: 5
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP IP tools
[](https://github.com/hiqdev/php-ip-tools/actions)
[](https://infection.github.io)
This library provides tooling for IP address calculations based on [rlanvin/php-ip](https://github.com/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:
```php
$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](blob/master/tests/Unit/IpBlocksCalculatorTest.php).
### IP ranges parsing
Parse fuzzy IP address block definitions and unwrap it to an array:
Example:
```php
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](blob/master/tests/Unit/IpRangeParseTest.php).