定制 littledevnl/iptools 二次开发

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

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

littledevnl/iptools

最新稳定版本:v1.2

Composer 安装命令:

composer require littledevnl/iptools

包简介

Small package for handling things with IPs and networks

README 文档

README

Latest Version on Packagist CI Mutation testing badge

This package is a set of tools for working with IP addresses and networks.

A lot of the internals are inspired by S1lentium/IPTools, but when using that package I noticed I started by wrapping everything I needed in separate classes. Which lead me to create my own package.

The state is pretty alpha at this point but feel free to use it. I do my best to not change the interfaces and facades if possible.

Installation

composer require littledevnl/iptools

Getting started

use Littledev\IPTools\Address;
use Littledev\IPTools\Network;
use Littledev\IPTools\Iterator\AddressIterator;
use Littledev\IPTools\Family\IPFamily;

$ip = Address::parse($_SERVER['REMOTE_ADDR']);
if ($ip->family() === IPFamily::v6()) {
    echo 'Good for you!';
}

$network6 = Network::parse('2001:db8::/64');
if ($network6->contains($ip)) {
    echo 'You use an IP which is reserved for documentation.';
}

$localNetwork = Network::parse('127.0.0.1/24');
if ($localNetwork->contains($ip)) {
    echo 'No place like localhost.';
}

$iterator = new AddressIterator($localNetwork);
foreach ($iterator as $address) {
    echo 'In local network: ' . $address->address();
}

Goals

  • No dependencies.
  • A set of tools for parsing and working with IP addresses and networks
  • Utility classes should be open for extension through a common parent

Changelog

  • [v0.1] Parsing of IP addresses and networks.
  • [v0.2] constains now accepts networks and addresses. Generalized
  • [v0.3] Network Iterators
  • [v0.4] Network lists
  • [v1.0] Reworked interfaces
  • [v1.1] Fixed composer PHP requirement, supports PHP7.4 and up
  • [v1.2] Fix for shorter inAddr inputs

Limitations

Not yet a complete set of tools, it is just the beginning.

Without external dependencies for things like arbitrary precision numbers, it is impossible to do certain things. For instance calculating the number of hosts in a IPV6 network. You can do it yourself with bcmath, see the example below

use Littledev\IPTools\Network;
use Littledev\IPTools\Family\IPFamily;

$net = Network::parse('2001:db8::/64');
$numbersOfAddresses =  bcpow('2', (string)(IPFamily::v6()->maxPrefix() - $net->subnet()->prefix()));

统计信息

  • 总下载量: 681
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固