定制 gwk/ip_address 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gwk/ip_address

最新稳定版本:0.2

Composer 安装命令:

composer require gwk/ip_address

包简介

IP address handling library

README 文档

README

This library allows you to handle IP addresses in various forms (currently IPv4 only) and test whether an IP matches certain constraints (equality, in a subnet or in a range).

Example

<?php

use IPAddress\IPv4\Address;
use IPAddress\IPv4\Subnet;

$address = new Address("1.2.8.200"); // These statements yield the same address
$address = new Address(0x010208c8);
$address = new Address(array(1, 2, 8, 200));
$address = new Address(array("1", "2", "010", "0xc8"));

$subnet = new Subnet("1.2.3.4", "255.255.0.0"); // These statements yield the same subnet
$subnet = Subnet::fromCidr("1.2.3.4", 16);
$subnet = Subnet::fromString("1.2.3.4 255.255.0.0");
$subnet = Subnet::fromString("1.2.3.4/16");

if($address->isPrivate()) {
    echo "Your address is in one of the RFC1918 Private networks.\n";
}

if($subnet->match($address)) {
    echo "I know your address is in the \"$subnet\" subnet.\n";
    // OUTPUT: I know your address is in the "1.2.3.4 netmask 255.255.0.0" subnet.
}

The library's test have been run on both 32-bit and 64-bit php and should work on both. Please note that the Address class' int() method (which returns the integer representation of an IP address) will return a negative number for ip addresses larger than 127.255.255.255 on 32-bit php due to the fact that php doesn't support unsigned integers.

TODO

  • More utility methods
  • IPv6 support

Disclaimer

I have limited knowledge of IP addresses so I could have made some mistakes regarding terminology or even behavior of the library in certain cases.

License

MIT, see LICENSE

统计信息

  • 总下载量: 11.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固