PHP code example of sherinbloemendaal / phpipam-client
1. Go to this page and download the library: Download sherinbloemendaal/phpipam-client 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/ */
sherinbloemendaal / phpipam-client example snippets
declare(strict_types=1);
use SherinBloemendaal\PhpIPAMClient\PhpIPAMClient;
use SherinBloemendaal\PhpIPAMClient\Connection\Connection;
// Initialize client with SSL (recommended)
$client = new PhpIPAMClient(
url: 'https://phpipam.example.com',
appID: 'myApp',
username: 'admin',
password: 'secret',
apiKey: '', // Not needed for SSL
securityMethod: Connection::SECURITY_METHOD_SSL
);
// Or initialize connection statically
Connection::initializeConnection(
url: 'https://phpipam.example.com',
appID: 'myApp',
username: 'admin',
password: 'secret'
);
use SherinBloemendaal\PhpIPAMClient\Controller\Section;
// Get all sections
$sections = Section::getAll();
// Get section by ID
$section = Section::getByID(1);
// Get section by name
$section = Section::getByName('Production');
// Create new section
$section = Section::post([
'name' => 'Development',
'description' => 'Development networks',
'strictMode' => true
]);
// Update section
$section->setDescription('Updated description')
->setStrictMode(false)
->patch();
// Delete section
$section->delete();
use SherinBloemendaal\PhpIPAMClient\Controller\Subnet;
use SherinBloemendaal\PhpIPAMClient\Controller\Section;
// Get all subnets
$subnets = Subnet::getAll();
// Create subnet in a section
$section = Section::getByName('Production');
$subnet = Subnet::post([
'subnet' => '192.168.1.0',
'mask' => 24,
'description' => 'Web servers',
'sectionId' => $section, // Can use object or ID
]);
// Get subnet usage
$usage = $subnet->getUsage();
// Get addresses in subnet
$addresses = $subnet->getAddresses();
// Find first free IP
$freeIP = $subnet->getFirstFree();
use SherinBloemendaal\PhpIPAMClient\Controller\Address;
// Search for IP address
$addresses = Address::getSearchByIP('192.168.1.100');
// Get address by IP and subnet
$address = Address::getByIPAndSubnet('192.168.1.100', $subnet);
// Create new address
$address = Address::postFirstFree($subnet, [
'hostname' => 'web01.example.com',
'description' => 'Web server',
'owner' => 'IT Department'
]);
// Update address
$address->setHostname('web01-new.example.com')
->setDescription('Updated web server')
->patch();