Re: Determine connectivity status



On Wed, 2010-03-10 at 20:07 +0100, Mads Kiilerich wrote:
> Mads Kiilerich wrote, On 03/10/2010 02:17 PM:
> > How can an application be made aware of the machines "online/offline" 
> > status? I assume there is a fine dbus method/event - but which?
> 
> Reply to self and archive: It is called State in NM lingo and can be 
> accessed as below.

Yup, you found it...  Out of curiosity, how easy was it to find out the
answer?

Dan

> /Mads
> 
> 
> #!/bin/env python
> """
> Sample code for getting and following NetworkManager "state".
> """
> # Based on:
> # - http://projects.gnome.org/NetworkManager/developers/spec-08.html
> # - test/nm-online.c (which however uses the depreciated state() method)
> # - http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html
> 
> from dbus.mainloop.glib import DBusGMainLoop
> DBusGMainLoop(set_as_default=True)
> 
> import dbus
> bus = dbus.SystemBus()
> proxy = bus.get_object("org.freedesktop.NetworkManager", 
> "/org/freedesktop/NetworkManager")
> 
> NM_STATE_UNKNOWN = 0 # The NetworkManager daemon is in an unknown state.
> NM_STATE_ASLEEP = 1 # The NetworkManager daemon is asleep and all 
> interfaces managed by it are inactive.
> NM_STATE_CONNECTING = 2 # The NetworkManager daemon is connecting a device.
> NM_STATE_CONNECTED = 3 # The NetworkManager daemon is connected.
> NM_STATE_DISCONNECTED = 4 # The NetworkManager daemon is disconnected.
> 
> state = proxy.Get("org.freedesktop.NetworkManager", "State",
>      dbus_interface="org.freedesktop.DBus.Properties")
> print 'Initial connected state:', state == NM_STATE_CONNECTED
> 
> def handle_StateChanged(state):
>      print 'Changed connected state:', state == NM_STATE_CONNECTED
> proxy.connect_to_signal('StateChanged', handle_StateChanged,
>      dbus_interface='org.freedesktop.NetworkManager')
> 
> import gobject
> loop = gobject.MainLoop()
> loop.run()
> 
> _______________________________________________
> NetworkManager-list mailing list
> NetworkManager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]