|
17 | 17 | # | ipv6: method: disabled |
18 | 18 | import sdbus |
19 | 19 | from sdbus_block.networkmanager import ( |
| 20 | + ConnectionType, |
20 | 21 | NetworkManagerSettings, |
21 | 22 | NetworkConnectionSettings, |
22 | 23 | ) |
23 | 24 |
|
24 | 25 |
|
25 | 26 | def list_connection_profiles_blocking() -> None: |
26 | | - for connection_path in NetworkManagerSettings().connections: |
27 | | - connection_settings = NetworkConnectionSettings(connection_path) |
28 | | - settings = connection_settings.get_settings() |
29 | | - connection = settings["connection"] |
30 | | - |
31 | | - # Skip connection profiles for bridges and wireless networks |
32 | | - if connection["type"][1] in ("bridge", "802-11-wireless"): |
33 | | - continue |
34 | | - |
35 | | - print("-------------------------------------------------------------") |
36 | | - print("name:", connection["id"][1]) |
37 | | - print("uuid:", connection["uuid"][1]) |
38 | | - print("type:", connection["type"][1]) |
39 | | - if "interface-name" in connection: |
40 | | - print(" interface-name:", connection["interface-name"][1]) |
41 | | - |
42 | | - if "ipv4" in settings: |
43 | | - ipv4 = settings["ipv4"] |
44 | | - print("ipv4: method:", ipv4["method"][1]) |
45 | | - if "address-data" in ipv4: |
46 | | - for a in ipv4["address-data"][1]: |
47 | | - print(f' ipaddr: {a["address"][1]}/{a["prefix"][1]}') |
48 | | - if "route-metric" in ipv4: |
49 | | - print(f' route-metric: {ipv4["route-metric"][1]}') |
50 | | - |
51 | | - if "ipv6" in settings: |
52 | | - print("ipv6: method:", settings["ipv6"]["method"][1]) |
| 27 | + """Call print_connection_profile_blocking() for all connection profiles""" |
| 28 | + networkmanager_settings = NetworkManagerSettings() |
| 29 | + for dbus_connection_path in networkmanager_settings.connections: |
| 30 | + print_connection_profile_blocking(dbus_connection_path) |
| 31 | + |
| 32 | + |
| 33 | +def print_connection_profile_blocking(connection_path: str) -> None: |
| 34 | + """Show the use of NetworkConnectionSettings(path).connection_profile()""" |
| 35 | + profile = NetworkConnectionSettings(connection_path).connection_profile() |
| 36 | + print("-------------------------------------------------------------") |
| 37 | + print("name:", profile.connection.connection_id) |
| 38 | + print("uuid:", profile.connection.uuid) |
| 39 | + print("type:", profile.connection.connection_type) |
| 40 | + if profile.connection.interface_name: |
| 41 | + print(" interface-name:", profile.connection.interface_name) |
| 42 | + if profile.ipv4: |
| 43 | + print("ipv4: method:", profile.ipv4.method) |
| 44 | + if profile.ipv4.address_data: |
| 45 | + for address in profile.ipv4.address_data: |
| 46 | + print(f' ipaddr: {address.address}/{address.prefix}') |
| 47 | + if profile.ipv4.route_metric: |
| 48 | + print(f' route-metric: {profile.ipv4.route_metric}') |
| 49 | + if profile.ipv6: |
| 50 | + print("ipv6: method:", profile.ipv6.method) |
| 51 | + if profile.connection.connection_type == ConnectionType.WIFI: |
| 52 | + assert profile.wireless |
| 53 | + assert profile.wireless.ssid |
| 54 | + print("ssid:", profile.wireless.ssid.decode()) |
53 | 55 |
|
54 | 56 |
|
55 | 57 | if __name__ == "__main__": |
|
0 commit comments