2016-04-28 01:27:25 +02:00
|
|
|
#!/usr/bin/python3
|
2015-03-26 06:11:18 +01:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import dbus
|
2016-07-26 14:42:57 +02:00
|
|
|
import collections
|
2015-03-26 06:11:18 +01:00
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
|
|
|
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
|
2016-05-21 03:39:37 +02:00
|
|
|
"org.freedesktop.DBus.ObjectManager")
|
|
|
|
objects = manager.GetManagedObjects()
|
|
|
|
|
2016-07-26 14:42:57 +02:00
|
|
|
Obj = collections.namedtuple('Obj', ['interfaces', 'children'])
|
|
|
|
tree = Obj({}, {})
|
2016-05-21 03:39:37 +02:00
|
|
|
for path in objects:
|
2016-07-26 14:42:57 +02:00
|
|
|
node = tree
|
|
|
|
elems = path.split('/')
|
|
|
|
for subpath in [ '/'.join(elems[:l + 1]) for l in range(1, len(elems)) ]:
|
|
|
|
if subpath not in node.children:
|
|
|
|
node.children[subpath] = Obj({}, {})
|
|
|
|
node = node.children[subpath]
|
|
|
|
node.interfaces.update(objects[path])
|
|
|
|
|
2020-02-15 01:17:47 +01:00
|
|
|
root = tree.children['/net'].children['/net/connman'].children['/net/connman/iwd']
|
|
|
|
for path, phy in root.children.items():
|
2016-07-26 14:42:57 +02:00
|
|
|
if 'net.connman.iwd.Adapter' not in phy.interfaces:
|
2016-05-21 03:39:37 +02:00
|
|
|
continue
|
|
|
|
|
2016-07-26 14:42:57 +02:00
|
|
|
properties = phy.interfaces['net.connman.iwd.Adapter']
|
2015-03-26 06:11:18 +01:00
|
|
|
|
|
|
|
print("[ %s ]" % path)
|
|
|
|
|
2016-07-14 02:38:07 +02:00
|
|
|
for key in properties:
|
|
|
|
val = properties[key]
|
2018-09-22 18:48:28 +02:00
|
|
|
if key == 'SupportedModes':
|
|
|
|
val = [str(mode) for mode in val]
|
2015-03-26 06:11:18 +01:00
|
|
|
print(" %s = %s" % (key, val))
|
|
|
|
|
2016-07-26 14:42:57 +02:00
|
|
|
print(" Devices:")
|
|
|
|
|
|
|
|
for path2, device in phy.children.items():
|
|
|
|
if 'net.connman.iwd.Device' not in device.interfaces:
|
|
|
|
continue
|
|
|
|
|
2016-05-21 03:39:37 +02:00
|
|
|
print(" [ %s ]" % path2)
|
2018-09-22 18:48:28 +02:00
|
|
|
for interface in device.interfaces:
|
|
|
|
name = interface.rsplit('.', 1)[-1]
|
|
|
|
if name not in ('Device', 'Station', 'AccessPoint', 'AdHoc'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
properties = device.interfaces[interface]
|
|
|
|
for key in properties:
|
|
|
|
val = properties[key]
|
|
|
|
print(" %s.%s = %s" % (name, key, val))
|
|
|
|
|
|
|
|
if name != 'Station':
|
|
|
|
continue
|
|
|
|
|
|
|
|
print(" Sorted networks:")
|
|
|
|
|
|
|
|
station = dbus.Interface(bus.get_object("net.connman.iwd", path2),
|
|
|
|
'net.connman.iwd.Station')
|
|
|
|
for path3, rssi in station.GetOrderedNetworks():
|
|
|
|
print(" [ %s ]" % path3)
|
|
|
|
|
|
|
|
properties2 = objects[path3]['net.connman.iwd.Network']
|
|
|
|
print(" SSID = %s" % (properties2['Name'],))
|
|
|
|
print(" Signal strength = %i dBm" % (rssi / 100,))
|
|
|
|
print(" Security = %s" % (properties2['Type'],))
|