How to automatically connect to open wireless network

Asked by tdn

How do I make my netbook automatically connect to any open wireless networks if they are available?
Even before a user is logged in?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gnome-nettool Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

You can add the network in /etc/network/interfaces but this will mean that network manager and apps like that will not be able to manipulate the device. You can use the interfaces file to configure the interface and it will be configured at bootup even before the users log on.

Revision history for this message
tdn (spam-thomasdamgaard) said :
#2

actionparsnip: That will not do. The users must be able to use network manager to change network as they please after logging in.

So far, I have come up with this zsh shellscript as a solution. Must be called with wireless network interface name as argument:

#!/bin/zsh
function randomline() {
    RANDOM=$(date +%N)
    local num_lines=0 line picked
    while read line; do
        (( (RANDOM % ++num_lines) == 0 )) && picked=$line
    done
    echo $picked
}

# Select a random open wireless network
ESSID=$(iwlist wlan0 scan |grep key:off -A2 |grep ESSID |cut -d':' -f2 | randomline)
IFACE=$1
iwconfig $IFACE mode Managed
iwconfig $IFACE essid $ESSID
dhclient $IFACE

Not pretty, but it kinda works.
If someone can suggest a more elegant solution, I am all ears.

Can you help with this problem?

Provide an answer of your own, or ask tdn for more information if necessary.

To post a message you must log in.