Skip to content

Cross-platform PHP library for scan, connect and disconnect Wi-Fi networks.

License

Notifications You must be signed in to change notification settings

sanchescom/php-wifi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maintainability StyleCI Quality Score

PHP WiFI

PHP WiFi is cross-platform php library base on integrated in OS utilities

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Installing

Require this package, with Composer, in the root directory of your project.

$ composer require sanchescom/php-wifi

Usage

<?php

use Sanchescom\WiFi\WiFi;

class Example
{
    public $device;

    /**
     * @throws Exception
     */
    public function getAllNetworks()
    {
        $allNetworks = WiFi::scan()->getAll();

        if (count($allNetworks) > 0) {
            foreach ($allNetworks as $network) {
                echo $network . "\n";
            }
        }
    }

    /**
     * @param $ssid
     * @param $password
     * @throws Exception
     */
    public function connect($ssid, $password)
    {
        $networks = WiFi::scan()
            ->getBySsid($ssid);

        if (count($networks) > 0) {
            $networks[0]->connect($password, $this->device);
        } else {
            echo "Network $ssid wasn't found!\r\n";
        }
    }

    /**
     * @throws Exception
     */
    public function disconnect()
    {
        $connectedNetworks = WiFi::scan()->getConnected();

        foreach ($connectedNetworks as $network) {
            $network->disconnect($this->device);
        }
    }
}

$example = new Example();
try {
    $example->device = 'en1';
    $example->getAllNetworks();
    $example->connect('Redmi', '12345');
    $example->disconnect();
} catch (Exception $e) {
    //
}

Running in console:

List of found wifi networks

$ ./vendor/bin/wifi list

List connected wifi networks

$ ./vendor/bin/wifi list --connected

Connect to wifi network

$ ./vendor/bin/wifi connect --bssid=4c:49:e3:f5:35:17 --password=12345 --device=en1

Disconnect from wifi network

$ ./vendor/bin/wifi disconnect --bssid=4c:49:e3:f5:35:17 --device=en1

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Platform support

  • Linux
  • MacOS
  • Windows

About

Cross-platform PHP library for scan, connect and disconnect Wi-Fi networks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published