2011-08-05 15:55:14 +02:00
|
|
|
#!/usr/bin/env python
|
2020-12-23 22:21:36 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-08-05 15:55:14 +02:00
|
|
|
#
|
|
|
|
|
# Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
|
#
|
|
|
|
|
|
2020-05-06 23:16:34 +02:00
|
|
|
import dbus
|
2011-08-05 15:55:14 +02:00
|
|
|
|
2020-06-30 16:21:00 -04:00
|
|
|
# This example lists all of the active connections
|
|
|
|
|
# the system is connected to and prints it out
|
2011-08-05 15:55:14 +02:00
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
|
|
|
|
|
# Get a proxy for the base NetworkManager object
|
2020-06-09 16:28:32 -04:00
|
|
|
m_proxy = bus.get_object(
|
|
|
|
|
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
|
|
|
|
|
)
|
2011-08-06 10:44:50 +02:00
|
|
|
mgr_props = dbus.Interface(m_proxy, "org.freedesktop.DBus.Properties")
|
|
|
|
|
|
2020-06-30 16:21:00 -04:00
|
|
|
# Find all active connections
|
2011-08-05 15:55:14 +02:00
|
|
|
active = mgr_props.Get("org.freedesktop.NetworkManager", "ActiveConnections")
|
2020-06-30 16:21:00 -04:00
|
|
|
|
2011-08-05 15:55:14 +02:00
|
|
|
for a in active:
|
|
|
|
|
a_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
|
2011-08-06 10:44:50 +02:00
|
|
|
|
2011-08-05 15:55:14 +02:00
|
|
|
a_props = dbus.Interface(a_proxy, "org.freedesktop.DBus.Properties")
|
2011-08-06 10:44:50 +02:00
|
|
|
|
|
|
|
|
# Grab the connection object path so we can get all the connection's settings
|
2020-06-09 16:28:32 -04:00
|
|
|
connection_path = a_props.Get(
|
|
|
|
|
"org.freedesktop.NetworkManager.Connection.Active", "Connection"
|
|
|
|
|
)
|
2011-08-06 10:44:50 +02:00
|
|
|
c_proxy = bus.get_object("org.freedesktop.NetworkManager", connection_path)
|
2020-06-09 16:28:32 -04:00
|
|
|
connection = dbus.Interface(
|
|
|
|
|
c_proxy, "org.freedesktop.NetworkManager.Settings.Connection"
|
|
|
|
|
)
|
2011-08-06 10:44:50 +02:00
|
|
|
settings = connection.GetSettings()
|
2020-06-09 16:28:32 -04:00
|
|
|
print(
|
|
|
|
|
"%s (%s) - %s"
|
2020-06-30 16:21:00 -04:00
|
|
|
% (
|
|
|
|
|
settings["connection"]["id"],
|
|
|
|
|
settings["connection"]["uuid"],
|
|
|
|
|
settings["connection"]["type"],
|
|
|
|
|
)
|
2020-06-09 16:28:32 -04:00
|
|
|
)
|
2011-08-05 15:55:14 +02:00
|
|
|
|
|
|
|
|
if len(active) == 0:
|
2017-12-02 12:44:50 +08:00
|
|
|
print("No active connections")
|