Skip to content

Commit cbf0f32

Browse files
author
Bernhard Kaindl
committed
Show the use of NetworkConnectionSettings(path).connection_profile()
1 parent 7dd4a75 commit cbf0f32

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

examples/block/list-connections.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,41 @@
1717
# | ipv6: method: disabled
1818
import sdbus
1919
from sdbus_block.networkmanager import (
20+
ConnectionType,
2021
NetworkManagerSettings,
2122
NetworkConnectionSettings,
2223
)
2324

2425

2526
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())
5355

5456

5557
if __name__ == "__main__":

0 commit comments

Comments
 (0)