1. Go to this page and download the library: Download mangospot/network-manager 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/ */
mangospot / network-manager example snippets
// 'vendor/autoload.php';
// 'import' NetworkInterfaces class
use NetworkManager\Networks;
// create new netif from ifconfig
$netif = new Networks();
// or create new netif from net_get_interfaces()
$netif = new Networks(false);
// gets the host name
$host = $netif->getHostAddr();
// get network interfaces
$interfaces = $netif->getNetworkInterfaces();
// get array network interfaces
$arrayInterface = $netif->arrayInterfaces();
// 'vendor/autoload.php';
// 'import' NetworkInterfaces class
use NetworkManager\Adaptor;
use NetworkManager\Interfaces;
// create new handle from /etc/networking/interfaces
$handle = new Interfaces();
// parse file
$handle->parse();
// add source on /etc/networking/interfaces
$handle->addSource();
// or add source dir
$handle->addSource('/etc/network/interfaces.d/*');
// create new Adaptor and set configs
$adaptor = new Adaptor();
$adaptor->name = "eth2";
$adaptor->family = "inet";
$adaptor->method = "static";
$adaptor->address = '192.168.2.100';
$adaptor->gateway = '192.168.2.1';
$adaptor->netmask = '255.255.255.0';
$adaptor->auto = true;
$adaptor->allows[] = 'hotplug';
$adaptor->Unknown['dns-nameservers'] = '8.8.8.8 8.8.4.4';
// add adaptor to NetworkInterfaces instance
$handle->add($adaptor);
// change eth0 ip address
$handle->Adaptors['eth0']->address = '192.168.0.30';
// Write changes to /etc/networking/interfaces
$handle->write();
// bringing up new interface
$handle->up('eth2');
// 'vendor/autoload.php';
// phpseclib3 class
use phpseclib3\Net\SSH2;
use phpseclib3\Net\SFTP;
class SSH extends SSH2 {
private $sftp;
public function __construct(){
parent::__construct('127.0.0.1', 22);
$this->login('username', 'password');
}
public function sftp(){
$this->sftp = new SFTP('127.0.0.1', 22);
$this->sftp->login('username', 'password');
return $this->sftp;
}
}
//nclude 'autoload.php';
// NetworkInterfaces class
use NetworkManager\Adaptor;
use NetworkManager\Networks;
use NetworkManager\Interfaces;
$SSH = new SSH();
$network = new Networks();
$interface = new Interfaces();
$network->ssh($SSH);
$interface->ssh($SSH);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.