6

I'm writing a small little app that I want to submit to the Ubuntu App Review board, and one thing I'd like to do is for it to show the names of the detected Wireless SSIDs in a combo box. It's a PyGI app.

Has anyone got any pointers on how I can get those SSIDs from the system, preferably through a Python API? From dbus? From NetworkManager?

David Planella
  • 15,420
  • 11
  • 77
  • 141

2 Answers2

13

You can do this easily from NetworkManager's pygi bindings:

from gi.repository import NetworkManager, NMClient

nmc = NMClient.Client.new()
devs = nmc.get_devices()

for dev in devs:
    if dev.get_device_type() == NetworkManager.DeviceType.WIFI:
        for ap in dev.get_access_points():
            print ap.get_ssid()

Or from DBus directly, see http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/show-bssids.py

If you're inclined to just quickly script this in shell; an easy way to ask NetworkManager for this is to use:

nmcli dev wifi list

Or use iwlist scan, or better: iw dev wlan0 scan (or ... scan dump), after installing the iw Install iw package.

  • 2
    I realise this is an old question, but is there a place where NetworkManager and NMClient are documented? – Chinmay Kanchi Dec 12 '13 at 10:18
  • See [python-networkmanager on GitHub](https://github.com/seveas/python-networkmanager) which links to [the documentation](http://packages.python.org/python-networkmanager/) :-) – bitinerant Jan 22 '19 at 21:49
3

One option is to run iwlist scan on the command line, but it has to be run as root

stephenmyall
  • 9,855
  • 15
  • 46
  • 67
mhall119
  • 5,017
  • 15
  • 25
  • Ah, that's something I can use, but I'd prefer accessing them at an API level rather than through command line and subprocess calls, so I think I'll end up accepting Mathieu's answer. In any case, thanks for your answer! – David Planella May 16 '12 at 14:30