cmdrsharp/ip-addressing

A collection of traits for IP Operations.

1.2.0.0 2019-08-21 20:31 UTC

This package is auto-updated.

Last update: 2024-11-22 08:24:35 UTC


README

Latest Stable Version Build Status StyleCI MIT licensed

A collection of traits for general IP operations. New traits may be added over time.

Current Requirements

  • PHP 7.1 or newer

Installation

Via composer

$ composer require cmdrsharp/ip-addressing

Usage

Use the applicable Trait in your classes.

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
	}
}

What trait contains what?

IPv4

  • getNetworkFromIp(string $ip, string $netmask): string
  • getBroadcastFromIp(string $ip, string $netmask): string

Subnet

  • getCidrFromNetmask(string $netmask): string

Versioning

This package follows Explicit Versioning.

Authors

CmdrSharp

License

The MIT License (MIT)