blob: 1ba156b6f8714fdcde4a181192c848324de7d8f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env python
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2010 Red Hat, Inc.
#
import dbus
# This example lists all of the active connections
# the system is connected to and prints it out
bus = dbus.SystemBus()
# Get a proxy for the base NetworkManager object
m_proxy = bus.get_object(
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
)
mgr_props = dbus.Interface(m_proxy, "org.freedesktop.DBus.Properties")
# Find all active connections
active = mgr_props.Get("org.freedesktop.NetworkManager", "ActiveConnections")
for a in active:
a_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
a_props = dbus.Interface(a_proxy, "org.freedesktop.DBus.Properties")
# Grab the connection object path so we can get all the connection's settings
connection_path = a_props.Get(
"org.freedesktop.NetworkManager.Connection.Active", "Connection"
)
c_proxy = bus.get_object("org.freedesktop.NetworkManager", connection_path)
connection = dbus.Interface(
c_proxy, "org.freedesktop.NetworkManager.Settings.Connection"
)
settings = connection.GetSettings()
print(
"%s (%s) - %s"
% (
settings["connection"]["id"],
settings["connection"]["uuid"],
settings["connection"]["type"],
)
)
if len(active) == 0:
print("No active connections")
|