3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program; if not, write to the Free Software Foundation, Inc.,
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
# Copyright (C) 2010 Red Hat, Inc.
23
def is_connection_up():
25
Returns True if network-manager reports that at least one connection is up
30
bus = dbus.SystemBus()
32
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
33
manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
35
manager_prop_iface = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
36
active = manager_prop_iface.Get("org.freedesktop.NetworkManager", "ActiveConnections")
38
ac_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
39
prop_iface = dbus.Interface(ac_proxy, "org.freedesktop.DBus.Properties")
40
state = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "State")
42
# Connections in NM are a collection of settings that describe everything
43
# needed to connect to a specific network. Lets get those details so we
44
# can find the user-readable name of the connection.
45
con_path = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "Connection")
46
con_service = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "ServiceName")
48
# ask the provider of the connection for its details
49
service_proxy = bus.get_object(con_service, con_path)
50
con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
51
con_details = con_iface.GetSettings()
52
con_name = con_details['connection']['id']
54
if state == 2: # activated