eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

list-devices (2368B)


      1 #!/usr/bin/python3
      2 
      3 import sys
      4 import dbus
      5 import collections
      6 
      7 bus = dbus.SystemBus()
      8 
      9 manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
     10                                         "org.freedesktop.DBus.ObjectManager")
     11 objects = manager.GetManagedObjects()
     12 
     13 Obj = collections.namedtuple('Obj', ['interfaces', 'children'])
     14 tree = Obj({}, {})
     15 for path in objects:
     16     node = tree
     17     elems = path.split('/')
     18     for subpath in [ '/'.join(elems[:l + 1]) for l in range(1, len(elems)) ]:
     19         if subpath not in node.children:
     20             node.children[subpath] = Obj({}, {})
     21         node = node.children[subpath]
     22     node.interfaces.update(objects[path])
     23 
     24 root = tree.children['/net'].children['/net/connman'].children['/net/connman/iwd']
     25 for path, phy in root.children.items():
     26     if 'net.connman.iwd.Adapter' not in phy.interfaces:
     27         continue
     28 
     29     properties = phy.interfaces['net.connman.iwd.Adapter']
     30 
     31     print("[ %s ]" % path)
     32 
     33     for key in properties:
     34         val = properties[key]
     35         if key == 'SupportedModes':
     36             val = [str(mode) for mode in val]
     37         print("    %s = %s" % (key, val))
     38 
     39     print("    Devices:")
     40 
     41     for path2, device in phy.children.items():
     42         if 'net.connman.iwd.Device' not in device.interfaces:
     43             continue
     44 
     45         print("    [ %s ]" % path2)
     46         for interface in device.interfaces:
     47             name = interface.rsplit('.', 1)[-1]
     48             if name not in ('Device', 'Station', 'AccessPoint', 'AdHoc'):
     49                 continue
     50 
     51             properties = device.interfaces[interface]
     52             for key in properties:
     53                 val = properties[key]
     54                 print("        %s.%s = %s" % (name, key, val))
     55 
     56             if name != 'Station':
     57                 continue
     58 
     59             print("        Sorted networks:")
     60 
     61             station = dbus.Interface(bus.get_object("net.connman.iwd", path2),
     62                                      'net.connman.iwd.Station')
     63             for path3, rssi in station.GetOrderedNetworks():
     64                 print("        [ %s ]" % path3)
     65 
     66                 properties2 = objects[path3]['net.connman.iwd.Network']
     67                 print("            SSID = %s" % (properties2['Name'],))
     68                 print("            Signal strength = %i dBm" % (rssi / 100,))
     69                 print("            Security = %s" % (properties2['Type'],))