--- /dev/null
+#!/bin/env python
+
+import dbus
+
+s_wired = dbus.Dictionary({'duplex': 'full'})
+s_con = dbus.Dictionary({
+ 'type': '802-3-ethernet',
+ 'uuid': '7371bb78-c1f7-42a3-a9db-5b9566e8ca07',
+ 'id': 'MyConnection'})
+
+addr1 = dbus.Array([dbus.UInt32(50462986L), dbus.UInt32(0L), dbus.UInt32(16908554L)], signature=dbus.Signature('u'))
+s_ip4 = dbus.Dictionary({
+ 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
+ 'method': 'manual'})
+
+s_ip6 = dbus.Dictionary({'method': 'ignore'})
+
+con = dbus.Dictionary({
+ '802-3-ethernet': s_wired,
+ 'connection': s_con,
+ 'ipv4': s_ip4,
+ 'ipv6': s_ip6})
+
+
+bus = dbus.SystemBus()
+
+proxy = bus.get_object("org.freedesktop.NetworkManagerSystemSettings", "/org/freedesktop/NetworkManagerSettings")
+settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings")
+
+settings.AddConnection(con)
+
--- /dev/null
+#!/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
+ if state == 8: # activated
+ print "Device %s is activated" % name
+ else:
+ print "Device %s is not activated" % name
+
+
+# Get active connection state
+manager_prop_iface = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
+active = manager_prop_iface.Get("org.freedesktop.NetworkManager", "ActiveConnections")
+for a in active:
+ ac_proxy = bus.get_object("org.freedesktop.NetworkManager", a)
+ prop_iface = dbus.Interface(ac_proxy, "org.freedesktop.DBus.Properties")
+ state = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "State")
+
+ # Connections in NM are a collection of settings that describe everything
+ # needed to connect to a specific network. Lets get those details so we
+ # can find the user-readable name of the connection.
+ con_path = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "Connection")
+ con_service = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "ServiceName")
+
+ # ask the provider of the connection for its details
+ service_proxy = bus.get_object(con_service, con_path)
+ con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
+ con_details = con_iface.GetSettings()
+ con_name = con_details['connection']['id']
+
+ if state == 2: # activated
+ print "Connection '%s' is activated" % con_name
+ else:
+ print "Connection '%s' is activating" % con_name
+
+