Skip to main content

A python library to control wpa_supplicant via it's control socket.

Project description

https://coveralls.io/repos/github/btimby/pywpas/badge.svg?branch=master https://github.com/btimby/pywpas/actions/workflows/ci.yml/badge.svg https://badge.fury.io/py/pywpas.svg

pywpas

A python library to control wpa_supplicant via it’s control socket.

Installation

pip install pywpas

Example

import time
import pywpas
# sock_path below is the default and can be omitted.
ctrl = pywpas.Control(sock_path='/var/run/wpa_supplicant)

# You can get a list of interface names:
interface_names = ctrl.interface_names()
print(interface_names)

# You can iterate over instances of the Interface class:
for interface in ctrl.interfaces:
    print(interface.name)

# You can get a specific Interface instance by name:
interface = ctrl.interface(interface_names[0])
print(interface.status())

# You can scan for networks available on an interface:
interface.scan()
# You might wait a few seconds...
time.sleep(5.0)
scan_results = interface.results()

for network in scan_results:
    print(network.ssid, network.signal_level)

# You can connect to a network (implictly adds a profile):
interface.connect(scan_results[0])
# Write the network to the wpa_supplicant.conf file:
interface.save_config()
# Then disconnect...
interface.disconnect()
# and remove the network:
interface.remove_network(scan_results[0])
# Or remove ALL networks:
interface.remove_networks()
interface.save_config()

# You can also add a profile (without connecting):
interface.add_network(scan_results[0])
# And save it:
interface.save_config()

# You can define a network and connect to it:
network = pywpas.Network(ssid='FOOBAR', ...)
interface.connect(network)
interface.disconnect()

# There is a high-level scan function, it will invoke callback
# with each unique network found during the scan timeout duration:
scan = interface.background_scan(lambda network: print(network.ssid),
                                 timeout=30.0)
time.sleep(5.0)
scan.stop()

wpa_supplicant configuration

You must configure wpa_supplicant to open a control socket. Optionally you can enable config file writing.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=nobody
update_config=1

Event with an emtpy configuation (no networks) you can use this library to add networks, connect to networks and save the profiles to the configuration file.

Development

To deploy to PyPI:

git tag <version>
git push --tags

CI will do the rest.

Tests and linting:

make test
make lint

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywpas-0.9.4.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywpas-0.9.4-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file pywpas-0.9.4.tar.gz.

File metadata

  • Download URL: pywpas-0.9.4.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pywpas-0.9.4.tar.gz
Algorithm Hash digest
SHA256 058a1e56e3f6fcce49c1de2e92a217e0d6f559b815488309c5d9e0bb0d2377f3
MD5 6ea300f142357262fee012151250c982
BLAKE2b-256 60e3f5dd05b3e00d908a5b21d372b3e77462c3e5a63dd399dab24e45d40cb932

See more details on using hashes here.

File details

Details for the file pywpas-0.9.4-py3-none-any.whl.

File metadata

  • Download URL: pywpas-0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pywpas-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 471897e0f5fe279ed5283ff072134848c83872f9ed1be36ac7ddebbd48590d41
MD5 5012af78b187ae12b17903076135ab82
BLAKE2b-256 9d0689aee09b7582c048291c1f0a0749730dc4a8fd5971888d7eeee2d67f61ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page