Note that there are some explanatory texts on larger screens.

plurals
  1. POConnecting to a protected WiFi from Python on Linux
    primarykey
    data
    text
    <p>I'm creating a software for Ubuntu Linux that needs to connect to a WiFi AP. The WiFi network is not predefined and can change several times during a single run of the software (the user is the one who orders the change). The idea is this: given a set of SSIDs and their WPA or WEP passphrases, the software should be able to switch between the networks on the whim, without the need to change any configuration files anywhere in the system.</p> <p>The huge problem, as it seems, is to pass the passphrase to the connection. Here's what I've been operating with so far:</p> <ul> <li>Ubuntu 12.10 machine equipped with a WiFi dongle.</li> <li>Python, which runs the software, and which will be used to request the connections</li> <li>connman 0.79</li> <li>wpa_supplicant v1.0</li> <li>d-bus</li> </ul> <p>At first I thought it would be possible to pass the passphrase to connman through d-bus, but neither this version of connman, nor 1.11, seem to expose any method for that. Then I found out that it's possible to dump a <code>service_&lt;SSID&gt;.conf</code> file to the <code>/var/lib/connman/</code> directory. Contents of the file are very simple and look like this:</p> <pre><code>[service_SSID] Type=wifi Name=Network-SSID Passphrase=here-goes-the-passphrase </code></pre> <p>Once this file is created, connecting to the network requires a simple call to net.connman.Service.Connect() method in appropriate service. The problem is that connman won't parse the config file unless it's restarted. This requires sudo privileges, additional time, and raises risk for all the "what can go wrong now" things to occur. Then I figured that passphrase could be somehow passed to the wpa_supplicant d-bus API, but I failed to find anything.</p> <p>Google searches have failed me too. It is as if no one ever tried to do this before.</p> <p>Command <code>sudo iwconfig wlan0 essid &lt;SSID&gt; key s:&lt;PASSPHRASE&gt;</code> results in a <code>SET failed on device wlan0 ; Invalid argument.</code> error. Also, it requires sudo which I would like to avoid.</p> <p>I tried to figure out how the wpa_gui program does its magic. First of all I discovered that it also requires sudo, and that it sends a bunch of commands directly to <code>/var/run/wpa_supplicant/wlan0</code>. Replicating this behavior would be a last resort for me if I don't figure out anything simplier.</p> <p>So, the big question is this: How to use Python in order to connect to a WEP/WPA protected WiFi network?<br> I'm also wondering if using connman is a good approach here and if I shouldn't revert to the Network Manager, which is Ubuntu's default.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload