PHP code example of cryental / php-wifi
1. Go to this page and download the library: Download cryental/php-wifi 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/ */
cryental / php-wifi example snippets
bash
$ composer
php
escom\WiFi\WiFi;
class Example
{
public $device;
/**
* @throws Exception
*/
public function getAllNetworks()
{
$networks = WiFi::scan()->getAll();
foreach ($networks as $network) {
echo $network . "\n";
}
}
/**
* @param $ssid
* @param $password
*/
public function connect($ssid, $password)
{
try {
WiFi::scan()->getBySsid($ssid)->connect($password, $this->device);
} catch (Exception $exception) {
echo $exception->getMessage();
}
}
/**
* @throws Exception
*/
public function disconnect()
{
$networks = WiFi::scan()->getConnected();
foreach ($networks as $network) {
$network->disconnect($this->device);
}
}
}
$example = new Example();
try {
$example->device = 'en1';
$example->getAllNetworks();
$example->connect('Redmi', '12345');
$example->disconnect();
} catch (Exception $e) {
//
}