Skip to content

Instantly share code, notes, and snippets.

@alex-eri
Created April 2, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-eri/a9439a99b289bca7ab6fc770afba23a7 to your computer and use it in GitHub Desktop.
Save alex-eri/a9439a99b289bca7ab6fc770afba23a7 to your computer and use it in GitHub Desktop.
from PyQt5.QtDBus import QDBusAbstractInterface, QDBusConnection
class Properties(QDBusAbstractInterface):
def __init__(self, parent=None):
super().__init__(parent.service(), parent.path(),
'org.freedesktop.DBus.Properties', parent.connection(), parent)
def __getitem__(self, name):
r = self.call('Get', self.parent().interface(), name)
if r:
r = r.arguments()
if r:
return r[0]
class BSS(QDBusAbstractInterface):
def __init__(self, path, parent=None):
super().__init__('fi.w1.wpa_supplicant1', path,
'fi.w1.wpa_supplicant1.BSS', QDBusConnection.systemBus(), parent)
self.Properties = Properties(parent=self)
@property
def SSID(self):
return self.Properties['SSID']
@property
def Signal(self):
return self.Properties['Signal']
class Interface(QDBusAbstractInterface):
def __init__(self, path, parent=None):
super().__init__('fi.w1.wpa_supplicant1', path,
'fi.w1.wpa_supplicant1.Interface', QDBusConnection.systemBus(), parent)
self.Properties = Properties(parent=self)
def Scan(self):
return self.call('Scan')
@property
def BSSs(self):
return [ BSS(i, self) for i in self.Properties['BSSs'] ]
class wpa_supplicant1(QDBusAbstractInterface):
def __init__(self, parent=None):
super().__init__('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1',
'fi.w1.wpa_supplicant1', QDBusConnection.systemBus(), parent)
self.Properties = Properties(parent=self)
@property
def Interfaces(self):
return [ Interface(i, self) for i in self.Properties['Interfaces'] ]
supplicant = wpa_supplicant1()
if supplicant.isValid():
for ifs in supplicant.Interfaces:
ifs.Scan()
for bss in ifs.BSSs:
print(bss.SSID.data().decode(), end='\t')
print(bss.Signal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment