This module provides a WiFiManager class for managing WiFi networks using nmcli,
and a WiFiNetwork dataclass to represent individual networks.
A dataclass representing a WiFi network.
- used (bool): Indicates whether the network is currently in use.
- bssid (str): The MAC address of the access point.
- ssid (str): The name of the WiFi network.
- mode (str): The mode of the network (e.g., infrastructure, ad-hoc).
- channel (int): The frequency channel the network is operating on.
- rate (str): The maximum data rate of the network.
- signal (int): The signal strength of the network.
- security (str): The security type of the network (e.g., WPA2, Open).
- to_dict()
- Converts the
WiFiNetworkobject to a dictionary.
- Converts the
- from_dict(data: dict)
- Populates the
WiFiNetworkobject from a dictionary.
- Populates the
A class for managing WiFi networks using nmcli.
-
rescan_networks()
- Triggers a WiFi scan using
nmcli. - Returns: Exit code of the
nmclicommand.
- Triggers a WiFi scan using
-
list_networks()
- Lists available WiFi networks, returning a list of
WiFiNetworkobjects. - Returns: List of
WiFiNetworkobjects.
- Lists available WiFi networks, returning a list of
-
disconnect()
- Disconnects from the current WiFi network.
- Returns: Exit code of the
nmclicommand.
-
connect(ssid: str, password: str)
- Connects to the specified WiFi network using a password.
- Parameters:
ssid(ssid): The WiFi network ssid to connect to.password(str): The password for the WiFi network.
- Returns: Exit code of the
nmclicommand.
-
create_hotspot(network: WiFiNetwork, password: str, device: str = 'wlan0')
- Connects to the specified WiFi network using a password.
- Parameters:
ssid(str): The WiFi network name.device(str): Device used to generate the network.password(str): The password for the WiFi network.
- Returns: Exit code of the
nmclicommand.
To use this module, you must have NetworkManager installed on your Linux system.
Run the following command:
sudo apt install network-manager # Debian/Ubuntu
sudo dnf install NetworkManager # Fedora
sudo pacman -S networkmanager # Arch Linuxgit clone https://github.com/Chopan25/python-wifi-manager.git
cd wifi-managerThis module relies on Python 3 and nmcli. Make sure Python is installed:
sudo apt install python3python3 setup.py installfrom wifi_manager import WiFiManager
networks = WiFiManager.list_networks()
for net in networks:
print(net.to_dict())
if networks:
WiFiManager.connect(networks[0], "your_password")python3 -m WiFiManager