承接 lifo/ip 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lifo/ip

最新稳定版本:v1.1.1

Composer 安装命令:

composer require lifo/ip

包简介

IP address helper PHP library for working with IPv4 and IPv6 addresses

README 文档

README

IP address helper PHP library for working with IPv4 and IPv6 addresses. Convert any IP address into decimal, hex or binary and back again.

Notes

This library is not complete and is missing certain CIDR, Subnet and other miscellaneous IP features. Most of the IP conversion routines use BCMATH to do calculations which means this library is not the fastest it could be. Once the library is in a more stable state I may start attempting to optimize certain bits.

Feel free to send pull requests with missing functionality.

Examples

The translation routines are IP agnostic, meaning they don't care if you pass in an IPv4 or IPv6 address. All IP calculations are done in Decimal which is perfect for storing in databases.

use Lifo\IP\IP;
use Lifo\IP\CIDR:

// IPv4
echo '127.0.0.1 = ', IP::inet_ptod('127.0.0.1'), "\n";
echo IP::inet_dtop('2130706433'), " = 2130706433\n";
echo '127.0.0.1 = ', IP::inet_ptoh('127.0.0.1'), " (hex)\n";

// IPv6
echo '2001:4056::1 = ', IP::inet_ptod('2001:4056::1'), "\n";
echo IP::inet_dtop('42541793049812452694190522094162280449'), " = 42541793049812452694190522094162280449\n";
echo '2001:4056::1 = ', IP::inet_ptoh('2001:4056::1'), " (hex)\n";

// CIDR 

// note: the true CIDR block is calculated from the prefix (the ::1 is ignored)
$ip = new CIDR('2001:4056::1/96');

echo "$ip\n", implode(' - ', $ip->getRange()), " (" . number_format($ip->getTotal()) . " hosts)\n";
// expected output:
127.0.0.1 = 2130706433
127.0.0.1 = 2130706433
127.0.0.1 = 7f000001 (hex)

2001:4056::1 = 42541793049812452694190522094162280449
2001:4056::1 = 42541793049812452694190522094162280449
2001:4056::1 = 20014056000000000000000000000001 (hex)

2001:4056::1/96
2001:4056:: - 2001:4056::ffff:ffff (4,294,967,296 hosts)

统计信息

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

GitHub 信息

  • Stars: 18
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

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