2011-08-05 15:55:14 +02:00
|
|
|
#!/usr/bin/env python
|
2019-09-10 11:19:01 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
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
|
|
|
|
|
|
|
|
# This example takes a device interface name as a parameter and tells
|
|
|
|
|
# NetworkManager to disconnect that device, closing down any network
|
|
|
|
|
# connection it may have
|
|
|
|
|
|
|
|
|
|
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
|
|
|
manager = dbus.Interface(m_proxy, "org.freedesktop.NetworkManager")
|
|
|
|
|
mgr_props = dbus.Interface(m_proxy, "org.freedesktop.DBus.Properties")
|
|
|
|
|
|
2020-06-09 16:28:32 -04:00
|
|
|
s_proxy = bus.get_object(
|
|
|
|
|
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings"
|
|
|
|
|
)
|
2011-08-06 10:44:50 +02:00
|
|
|
settings = dbus.Interface(s_proxy, "org.freedesktop.NetworkManager.Settings")
|
2011-08-05 15:55:14 +02:00
|
|
|
|
|
|
|
|
# Find the device the user wants to disconnect
|
|
|
|
|
active = mgr_props.Get("org.freedesktop.NetworkManager", "ActiveConnections")
|
|
|
|
|
for a in active:
|
|
|
|
|
a_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
|
2011-08-06 10:44:50 +02:00
|
|
|
|
|
|
|
|
# Get the UUID directly; apps could use this to perform certain operations
|
|
|
|
|
# based on which network you're connected too
|
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
|
|
|
uuid = a_props.Get("org.freedesktop.NetworkManager.Connection.Active", "Uuid")
|
|
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
% (settings["connection"]["id"], uuid, settings["connection"]["type"])
|
|
|
|
|
)
|
2011-08-05 15:55:14 +02:00
|
|
|
|
|
|
|
|
if len(active) == 0:
|
2017-12-02 12:44:50 +08:00
|
|
|
print("No active connections")
|