watch network connections with dbus and ruby

four portland area tech entrepreneurs launched automatic checkin is an important way to get services like these to be used. the dbus message system on linux machines is a great way to passively detect connections to a wireless network. using the package 'ruby-dbus-0.2.1', this is all it takes to be notified of any change in network status. note this prints any change including signal strength. i believe the [3] value is association to a new network.

require 'dbus' bus = DBus::SystemBus.instance

register for signals

mr = mr.type = "signal" mr.interface = "org.freedesktop.NetworkManager" mr.path = "/org/freedesktop/NetworkManager" bus.add_match(mr) do |msg, first_param| puts msg.params.inspect end

Main loop

main = main << bus /typo:code

The output looks like:

["/org/freedesktop/NetworkManager/Devices/wlan0", 100] (using the applet, re-associate now)
["/org/freedesktop/NetworkManager/Devices/wlan0", 89]
["/org/freedesktop/NetworkManager/Devices/wlan0", 4]
["/org/freedesktop/NetworkManager/Devices/wlan0", 99]
["/org/freedesktop/NetworkManager/Devices/wlan0", 100]
["/org/freedesktop/NetworkManager/Devices/wlan0", 5]
["/org/freedesktop/NetworkManager/Devices/wlan0", 6]
["/org/freedesktop/NetworkManager/Devices/wlan0", 7]
[3] (use this for network association hook?)
["/org/freedesktop/NetworkManager/Devices/wlan0", ""]
["/org/freedesktop/NetworkManager/Devices/wlan0", "/org/freedesktop/NetworkManager/Devices/wlan0/Networks/www_2e_personaltelco_2e_net", 77]

Using the [3] or the essid announcement as a trigger, an http post could be launched to report to shizzow or plazes of one's current location. This would be packaged into a .deb file for ubuntu and launched as a daemon at startup.