cmdrsharp / ip-addressing
一组用于IP操作的特性。
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: 2024-09-22 08:02:10 UTC
README
一组通用IP操作的特性。可能会随时间添加新特性。
当前需求
- PHP 7.1或更高版本
安装
通过composer
$ composer require cmdrsharp/ip-addressing
使用方法
在您的类中使用相应的特性。
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 } }
哪些特性包含什么?
IPv4
getNetworkFromIp(string $ip, string $netmask): stringgetBroadcastFromIp(string $ip, string $netmask): string
子网
getCidrFromNetmask(string $netmask): string
版本控制
此包遵循 显式版本控制。