2017 © Pedro Peláez
 

library ipv4

IPv4 classes for PHP

image

colinodell/ipv4

IPv4 classes for PHP

  • Friday, July 14, 2017
  • by colinodell
  • Repository
  • 1 Watchers
  • 5 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

IPv4 classes for PHP

Latest Version Total Downloads Software License Build Status Coverage Status Quality Score, (*1)

Purpose

Identify, convert, and enumerate IPv4 IP addresses and subnets, (*2)

Installation

Install with Composer: composer require colinodell/ipv4, (*3)

Examples

<?php

use ColinODell\Ipv4\Address;
use ColinODell\Ipv4\Subnet;

$ip = Address::fromString('10.2.1.1');
$sn = Subnet::fromString('10.2.0.0/16');

// Subnets can also be created like this:
$sn = new Subnet('192.168.1.0/24');
$sn = new Subnet('192.168.1.0', '255.255.255.0');
$sn = new Subnet(Address::fromString('192.168.1.0'), Address::fromString('255.255.255.0'));
$sn = new Subnet('192.168.1.0 255.255.255.0');
$sn = Subnet::fromString('192.168.1.0/24');
$sn = Subnet::fromString('192.168.1.0 255.255.255.0');

// Test if IP is in subnet
$sn->contains($ip)          // true
$sn->contains('10.3.1.23')  // false
Subnet::containsAddress($sn,$ip)
Subnet::containsAddress('192.168.1.0/27','192.168.1.246')

// Test if two IPs are on the same network
$netmask = '255.255.255.0';
Subnet::containsAddress(new Subnet($ip1,$netmask),$ip2)

// Can be written in numerous ways...
Subnet::containsAddress("{$ip1}/24",$ip2)
Subnet::fromString("{$ip1}/24")->contains($ip2)

// Subnet information
$sn->getNetwork()
$sn->getNetmask()
$sn->getNetmaskCidr()
$sn->getFirstHostAddr()
$sn->getLastHostAddr()
$sn->getBroadcastAddr()

// Enumerate subnet addresses
foreach($sn as $addr) ...

// Count number of usable IPs on subnet (implements Countable)
$sn->getTotalHosts()
$sn->count()
count($sn)

The Versions

14/07 2017

dev-master

9999999-dev

IPv4 classes for PHP

  Sources   Download

MIT

The Requires

  • php ^5.3.3|^7.0

 

The Development Requires

by Kelly Hallman

13/07 2017

1.0.0

1.0.0.0

IPv4 classes for PHP

  Sources   Download

MIT

The Requires

  • php ^5.3.3|^7.0

 

The Development Requires

by Kelly Hallman