Managing WiFi networks¶
You can use this library to scan for networks that are available in the air. To get a list of the different cells in the area, you can do
>>> from wifi import Cell, Scheme >>> Cell.all('wlan0')
This returns a list of
Cell objects. Under the hood, this calls iwlist scan and parses the unfriendly output.
Each cell object should have the following attributes:
For cells that have
encrypted as True, there will also be the following attributes:
Scanning requires root permission to see all the networks. If you are not root, iwlist only returns the network you are currently connected to.
Connecting to a network¶
In order to connect to a network, you need to set up a scheme for it.
>>> cell = Cell.all('wlan0') >>> scheme = Scheme.for_cell('wlan0', 'home', cell) >>> scheme.save() >>> scheme.activate()
Once you have a scheme saved, you can retrieve it using
>>> scheme = Scheme.find('wlan0', 'home') >>> scheme.activate()
Activating a scheme will disconnect from any other scheme before connecting.
You must be root to connect to a network. Wifi uses ifdown and ifup to connect and disconnect.
Presents a Python interface to the output of iwlist.
Returns a list of all cells extracted from the output of iwlist.
Parses the output of iwlist scan for one cell and returns a Cell object for it.
Scheme(interface, name, options=None)¶
Saved configuration for connecting to a wireless network. This class provides a Python interface to the /etc/network/interfaces file.
Connects to the network as configured in this scheme.
Returns an generator of saved schemes.
Deletes the configuration from the
for_cell(interface, name, cell, passkey=None)¶
A class factory for providing a nice way to specify the interfaces file that you want to use. Use this instead of directly overwriting the interfaces Class attribute if you care about thread safety.
Writes the configuration to the