Nathan Hoad

python-iwlib - simple wireless interface for Linux

April 23, 2013

Interfacing with Linux’s wireless tools from Python is, plainly put, awful. All existing solutions I’ve come across either parse the output of command line tools, or use a mixture of ioctl, array.array() objects and the struct module to get what you want. Not exactly maintainable or sane.

There was one Python module I can across, called python-iwlib, developed by some Redhat/Fedora folks to provide the output of iwconfig in a much more programmatic way, using the C API to retrieve the information. It had been orphaned since 2012, so I’ve taken ownership in the hopes of bringing it more up to speed.

What does it give you, now? Here’s a short list:

  1. Access point scanning.
  2. Setting the essid of a device.
  3. Check if an interface supports scanning.

That’s just a start - the wireless_tools package is huge, but my eventual plan is to provide a native interface for the complete toolset, all in Python, with no need to use the things I mentioned earlier.

If you find a feature missing, then submit a feature request. If the wireless_tools package can do it, python-iwlib can. I’m more than happy to implement things as people require them, and that’s probably the only way it’s going to get many of the features that I won’t use, because I’m not implementing the entire thing for nothing :)

I’ve tested it in CPython 2.7, and it works as expected. I’d love more people to use it, to get more of an idea how well it works against different versions of wireless_tools and CPython.

In the future I’d like to work towards implementing it in CFFI, so that PyPy can make use of the library as well.

You can check the code out on PyPi and Bitbucket. If you feel you can contribute, please do!