Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Build Status

IP is an immutable value object for (both version 4 and 6) IP addresses. Several helper methods are provided for ranges, broadcast and network addresses, subnet masks, whether an IP is a certain type (defined by RFC's), etc.

This project aims for simplicity of use and any contribution towards that goal - whether a bug report, modifications to the codebase, or an improvement to the accuracy or readability of the documentation - are always welcome.


Full documentation is available in the docs/ folder.


This library is fairly similar to how it was in 3.3.1; the main differences are:

Brief Example


use Darsyn\IP\Exception;
use Darsyn\IP\Version\IPv4;

try {
    $ip = IPv4::factory('');
} catch (Exception\InvalidIpAddressException $e) {
    exit('The IP address supplied is invalid!');

$companyNetwork = IPv4::factory('');
if (!$ip->inRange($companyNetwork, 25)) {
    throw new \Exception('Request not from a known company IP address.');

// Is it coming from the local network?
if (!$ip->isPrivateUse()) {
    record_visit($ip->getBinary(), $_SERVER['HTTP_USER_AGENT']);


Please see the separate license file included in this repository for a full copy of the MIT license, which this project is licensed under.


If you make a contribution (submit a pull request), don't forget to add your name here!