Querying network state via D-Bus; unexpected result values
- From: Adam Tauno Williams <awilliam whitemice org>
- To: networkmanager-list gnome org
- Subject: Querying network state via D-Bus; unexpected result values
- Date: Sun, 27 Nov 2011 20:14:07 -0500
I'm attempting to interrogate the state of the network condition via
Network Manager's D-Bus service. I can reliably get a value, but the
value seems incorrect.
According to
<http://projects.gnome.org/NetworkManager/developers/spec-07.html#type-NM_DEVICE_STATE> I expect to see a value of 8 [NM_DEVICE_STATE_ACTIVATED] if the device is online. But what I see from call is generally a 20 if the interface [Device 0, eth0] is unplugged and a value of 100 if the interface is
online.
#!/bin/env python
import dbus
bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager")
manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
# Get device-specific state
devices = manager.GetDevices()
for d in devices:
dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties")
# Get the device's current state and interface name
state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State")
name = prop_iface.Get("org.freedesktop.NetworkManager.Device",
"Interface")
# and print them out
print state
if state == 8: # activated
print "Device %s is activated" % name
else:
print "Device %s is not activated" % name
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]