Created
July 26, 2014 20:28
-
-
Save hfs/eb75d55680edd55d320d to your computer and use it in GitHub Desktop.
Query NetworkManager via DBUS in Python: Get the SSID of the active wireless connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import dbus | |
NM = 'org.freedesktop.NetworkManager' | |
NMCA = NM + '.Connection.Active' | |
NMDW = NM + '.Device.Wireless' | |
NMAP = NM + '.AccessPoint' | |
DBUS_PROPS = 'org.freedesktop.DBus.Properties' | |
def main(): | |
bus = dbus.SystemBus() | |
nm = bus.get_object(NM, '/org/freedesktop/NetworkManager') | |
conns = nm.Get(NM, 'ActiveConnections', dbus_interface=DBUS_PROPS) | |
conn = conns[0] | |
active_conn = bus.get_object(NM, conn) | |
devices = active_conn.Get(NMCA, 'Devices', dbus_interface=DBUS_PROPS) | |
dev_name = devices[0] | |
dev = bus.get_object(NM, dev_name) | |
ap_name = dev.Get(NMDW, 'ActiveAccessPoint', dbus_interface=DBUS_PROPS) | |
ap = bus.get_object(NM, ap_name) | |
ssid = ap.Get(NMAP, 'Ssid', dbus_interface=DBUS_PROPS, byte_arrays=True) | |
print(ssid) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment