Making Perl location-aware, one bit at a time

One of my long-term ideas is to make my laptop more location aware and to have something like cron except for locations instead of time. It will be useful to automatically reconfigure my network and proxy settings in Firefox and Thunderbird and to prevent information leakage. Also, my laptop can automatically synchronize its minicpan and git repositories with the mothership when it detects that a "fast" or "local" network connection is available.

As I'm not really interested (yet) in the physical location, it is enough for the laptop to know what wireless networks are visible to determine how it should behave. Later (or once GPS sensors become commonplace in laptops, or Perl becomes commonplace on GPS-enabled devices), adding GPS detection etc. will also become interesting.

As a first step, I've written a component that should get me a long way in the right direction. Win32::Wlan can read the list of currently visible wireless networks, and can also read what wireless network(s) the computer currently is associated with, and what encryption is available. This should be enough to drive a small rule engine that fires off scripts that handle the transitions between "no network" / "known network" / "unknown network" etc.

Win32::Wlan is in very rough shape. This is why I haven't released it onto CPAN yet. It uses Win32::API, which is somewhat unfortunate, as that precludes its use with a 64bit Perl. On the upside, it does not need any extra C headers installed. For going native, the wlanapi.h header file needs to be available. MinGW does not have that header file available, and the version that is freely distributable, a reimplementation by Google, is missing interesting functions. Once I get Win32::Wlan a bit of use, I will likely wrap it in a nicer API than the raw Windows C API, so that managing the various handles becomes more automatic. It would of course be nice to also have a Wlan API for other operating systems, and to maybe find a common ground, but as I know nothing about how other OSes handle Wlan, I'll first work on solving my immediate problem...

For the time being, Win32::Wlan lives at https://github.com/Corion/Win32-Wlan, until it climbs the fence and escapes onto CPAN.

Leave a comment

About Max Maischein

user-pic I'm the Treasurer for the Frankfurt Perlmongers e.V. . I have organized Perl events including 9 German Perl Workshops and one YAPC::Europe.