1. Go to this page and download the library: Download sanchescom/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/ */
sanchescom / php-wifi example snippets
use Sanchescom\WiFi\WiFi;
// Scan for all available networks
$networks = WiFi::scan();
// Get all networks as array
foreach ($networks->getAll() as $network) {
echo sprintf(
"SSID: %s, Signal: %.2f dBm, Channel: %d, Security: %s\n",
$network->ssid,
$network->dbm,
$network->channel,
$network->security
);
}
use Sanchescom\WiFi\WiFi;
$device = 'en0'; // macOS: en0, en1; Linux: wlan0, wlan1; Windows: use netsh
try {
// Connect to a specific network
$network = WiFi::scan()->getBySsid('My-WiFi-Network');
$network->connect('password123', $device);
echo "Connected successfully!\n";
} catch (Exception $e) {
echo "Connection failed: " . $e->getMessage() . "\n";
}
// Disconnect from all connected networks
$connectedNetworks = WiFi::getConnected();
foreach ($connectedNetworks as $network) {
$network->disconnect($device);
}
use Sanchescom\WiFi\WiFi;
// Get only 5GHz networks
$networks5ghz = WiFi::scan()->get5GhzNetworks();
// Get only 2.4GHz networks
$networks24ghz = WiFi::scan()->get24GhzNetworks();
// Filter by security type
$wpa2Networks = WiFi::scan()->getBySecurity('WPA2');
// Get networks with strong signal (above -60 dBm)
$strongNetworks = WiFi::scan()->getByMinSignalStrength(-60);
// Get networks on specific channel
$channel6Networks = WiFi::scan()->getByChannel(6);
// Combine filters (fluent interface)
$strongWPA2Networks = WiFi::scan()
->getBySecurity('WPA2')
->getByMinSignalStrength(-50)
->get5GhzNetworks();
use Sanchescom\WiFi\WiFi;
use Sanchescom\WiFi\Exceptions\NetworkNotFoundException;
try {
// Get the strongest available network
$strongestNetwork = WiFi::getStrongestNetwork();
echo "Strongest network: {$strongestNetwork->ssid} ({$strongestNetwork->dbm} dBm)\n";
// Find network by SSID
$network = WiFi::scan()->getBySsid('MyNetwork');
// Find network by BSSID (MAC address)
$network = WiFi::scan()->getByBssid('4c:49:e3:f5:35:17');
} catch (NetworkNotFoundException $e) {
echo "Network not found!\n";
}
use Sanchescom\WiFi\WiFi;
// Sort networks by signal strength (strongest first)
$sortedNetworks = WiFi::scan()->sortBySignalStrength();
foreach ($sortedNetworks as $network) {
echo "{$network->ssid}: {$network->dbm} dBm\n";
}