PHP code example of librenms / ip-util

1. Go to this page and download the library: Download librenms/ip-util library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

librenms / ip-util example snippets


try {
    $ip = new IP('192.168.1.1');
    // or
    $ip = IP::parse('192.168.1.1');
} catch (InvalidIpException $e) {
    //
}

IP::isValid('192.168.1.333');

$ip = IPv4::parse('192.168.1.1');
$ip = IPv6::parse('2600::');

IPv4::isValid('192.168.1.1');
IPv6::isValid('2600::');

echo $ip; // print nicely formated IP with cidr/prefix

echo $ip->address; // print just the address
echo $ip->cidr; // print the prefix length

echo $ip->compressed(); // Compresses IP addresses for easy reading
echo $ip->uncompressed(); // Uncompresses IP addresses for easy parsing

if ($ip->inNetwork('192.168.1.1/24')) {
    echo $ip->getNetwork();
}

$ip = IP::fromHexString('c0a801fe');