The dbus-networkdevices library empowers Python applications to get the active network devices that are connected to your network.
- IP Access: Retrieve interface name, ip addresses, wifi ssid, etc...
- Real-time Updates: Utilizes callback functions to provide instant updates of network changes.
- Python 3.7 or later
jeepneylibrary
Install the library using pip:
pip install dbus-networkdevicesThis library offers two primary usage approaches:
Run the script directly to print active network devices as JSON:
dbus-networkdevicesImport the DBUSNetworkDevices class from your Python code:
import json
import time
from dbus_networkdevices import DBUSNetworkDevices
def callback(devices):
# Handle the list of network devices here
print(json.dumps(devices, indent=2))
# Create an instance of the class
DBUSNetworkDevices(callback)
# Keep the app running
while True:
time.sleep(1)Most python applications use iwgetid and information from /proc/net/wireless to get the WiFi status, so I created this library to get the information directly from DBus and also include other interfaces.