luzrain/ipcalc
最新稳定版本:v2.0.0
Composer 安装命令:
composer require luzrain/ipcalc
包简介
IPv4/IPv6 Network calculator for PHP
README 文档
README
This IP Network Calculator library supports both IPv4 and IPv6, offering functionality to compute usable host ranges, retrieve subnet masks, and determine whether a given IP address belongs to a specific network.
Installation
Install with composer:
$ composer require luzrain/ipcalc
Usage
Create IPCalc\IP instance
$net = new IPCalc\IP('192.168.1.1/24'); // or $net = new IPCalc\IP('192.168.1.1', 24);
You can then retrieve various properties of the network:
$net->getIp(); // 192.168.1.1 // The original IP address $net->getNetmask(); // 255.255.255.0 // Subnet mask $net->getCidr(); // 24 // CIDR prefix length $net->getVersion(); // 4 // IP version (4 or 6) $net->isPrivate(); // true // Returns true if the IP address is in a private range $net->getNetwork(); // 192.168.1.0 // Network address of the subnet (IPv4 only) $net->getBroadcast(); // 192.168.1.255 // Broadcast address of the network (IPv4 only) $net->getHostMin(); // 192.168.1.1 // First usable IP address in the subnet $net->getHostMax(); // 192.168.1.254 // Last usable IP address in the subnet $net->contains('192.168.1.10'); // true // Returns true if the given IP address is within the network
Notes:
Although IPv6 does not use the concept of networks and broadcasts, the ranges are still needed to do inclusive searches. Also, IPv6 has a subnet segment, but can still be supernetted/subnetted, which this takes into consideration.
统计信息
- 总下载量: 14.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-09