You are not logged in.

#1 2012-04-25 13:36:54

nesneros
Member
From: Arizona
Registered: 2012-04-25
Posts: 20

Wireless auto-connect

Hello everyone, though the title may seem somewhat conveluted or mis-leading or incorrect.. whatever it may be.  I was wondering, what is the preferred method of having a laptop and or desktop (personally I do not use wireless on my desktop) connect to a wireless network on boot?  I have been using wicd, but wanted to get a feel for what others have been using.  I have seen some various bash scripts that run at startup that achieve the same thing as well.

Thoughts, input?


{ github | arch }

Offline

#2 2012-04-25 15:19:17

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Wireless auto-connect

I use wicd too and i think it works fine, but you can try out some of the other auto-wireless tools to see if you like them:

https://wiki.archlinux.org/index.php/Wi … atic_setup


ᶘ ᵒᴥᵒᶅ

Offline

#3 2012-04-25 15:54:10

nesneros
Member
From: Arizona
Registered: 2012-04-25
Posts: 20

Re: Wireless auto-connect

litemotiv wrote:

I use wicd too and i think it works fine, but you can try out some of the other auto-wireless tools to see if you like them:

https://wiki.archlinux.org/index.php/Wi … atic_setup

I will probably stick with wicd, was just kind of curious as to what other were using tongue -- thank you none the less litemotiv


{ github | arch }

Offline

#4 2012-04-25 17:09:27

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: Wireless auto-connect

I use wpa_auto, which in turn uses wpa_supplicant, which I find the most straightforward and easy to use. I also have a python script that parses the results of `iwlist wlan0 scan` so I can see, in a nice list, the available networks and their access points, in the cases that I need to connect to a new network.


Registed Linux User 483618

Offline

#5 2012-04-25 17:26:08

nesneros
Member
From: Arizona
Registered: 2012-04-25
Posts: 20

Re: Wireless auto-connect

Sara wrote:

I use wpa_auto, which in turn uses wpa_supplicant, which I find the most straightforward and easy to use. I also have a python script that parses the results of `iwlist wlan0 scan` so I can see, in a nice list, the available networks and their access points, in the cases that I need to connect to a new network.

The latter (python script) sounds intriguing, would you mind sharing it at all?


{ github | arch }

Offline

#6 2012-04-25 18:47:08

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: Wireless auto-connect

nesneros wrote:

The latter (python script) sounds intriguing, would you mind sharing it at all?

Sure! I didn't write it, but I was lucky enough to find it. Here it is, below:

#!/usr/bin/env python2
#
# iwlistparse.py
# Hugo Chargois - 17 jan. 2010 - v.0.1
# Parses the output of iwlist scan into a table

import sys

# You can add or change the functions to parse the properties of each AP (cell)
# below. They take one argument, the bunch of text describing one cell in iwlist
# scan and return a property of that cell.

def get_name(cell):
    return matching_line(cell,"ESSID:")[1:-1]

def get_quality(cell):
    quality = matching_line(cell,"Quality=").split()[0].split('/')
    return str(int(round(float(quality[0]) / float(quality[1]) * 100))).rjust(3) + " %"

def get_channel(cell):
    return matching_line(cell,"Channel:")

def get_encryption(cell):
    enc=""
    if matching_line(cell,"Encryption key:") == "off":
        enc="Open"
    else:
        for line in cell:
            matching = match(line,"IE:")
            if matching!=None:
                wpa=match(matching,"WPA Version ")
                if wpa!=None:
                    enc="WPA v."+wpa
        if enc=="":
            enc="WEP"
    return enc

def get_address(cell):
    return matching_line(cell,"Address: ")

# Here's a dictionary of rules that will be applied to the description of each
# cell. The key will be the name of the column in the table. The value is a
# function defined above.

rules={"Name":get_name,
       "Quality":get_quality,
       "Channel":get_channel,
       "Encryption":get_encryption,
       "Address":get_address,
       }

# Here you can choose the way of sorting the table. sortby should be a key of
# the dictionary rules.

def sort_cells(cells):
    sortby = "Quality"
    reverse = True
    cells.sort(None, lambda el:el[sortby], reverse)

# You can choose which columns to display here, and most importantly in what order. Of
# course, they must exist as keys in the dict rules.

columns=["Name","Address","Quality","Channel","Encryption"]




# Below here goes the boring stuff. You shouldn't have to edit anything below
# this point

def matching_line(lines, keyword):
    """Returns the first matching line in a list of lines. See match()"""
    for line in lines:
        matching=match(line,keyword)
        if matching!=None:
            return matching
    return None

def match(line,keyword):
    """If the first part of line (modulo blanks) matches keyword,
    returns the end of that line. Otherwise returns None"""
    line=line.lstrip()
    length=len(keyword)
    if line[:length] == keyword:
        return line[length:]
    else:
        return None

def parse_cell(cell):
    """Applies the rules to the bunch of text describing a cell and returns the
    corresponding dictionary"""
    parsed_cell={}
    for key in rules:
        rule=rules[key]
        parsed_cell.update({key:rule(cell)})
    return parsed_cell

def print_table(table):
    widths=map(max,map(lambda l:map(len,l),zip(*table))) #functional magic

    justified_table = []
    for line in table:
        justified_line=[]
        for i,el in enumerate(line):
            justified_line.append(el.ljust(widths[i]+2))
        justified_table.append(justified_line)

    for line in justified_table:
        for el in line:
            print el,
        print

def print_cells(cells):
    table=[columns]
    for cell in cells:
        cell_properties=[]
        for column in columns:
            cell_properties.append(cell[column])
        table.append(cell_properties)
    print_table(table)

def main():
    """Pretty prints the output of iwlist scan into a table"""
    cells=[[]]
    parsed_cells=[]

    for line in sys.stdin:
        cell_line = match(line,"Cell ")
        if cell_line != None:
            cells.append([])
            line = cell_line[-27:]
        cells[-1].append(line.rstrip())

    cells=cells[1:]

    for cell in cells:
        parsed_cells.append(parse_cell(cell))

    sort_cells(parsed_cells)

    print_cells(parsed_cells)

main()

To use, run

iwlist wlan0 scan | iwlistparse.py

where iwlistparse.py is in your PATH. I've aliased iwlist to that aforementioned command so I just run `sudo iwlist` when I want to see the available networks. (If I don't run it with sudo, only the network I'm currently connected to is displayed, rather than all the networks in my vicinity).

Last edited by Sara (2012-04-25 18:49:03)


Registed Linux User 483618

Offline

#7 2012-04-25 19:22:33

nesneros
Member
From: Arizona
Registered: 2012-04-25
Posts: 20

Re: Wireless auto-connect

Sara wrote:

Sure! I didn't write it, but I was lucky enough to find it. Here it is, below:

#!/usr/bin/env python2
#
# iwlistparse.py
# Hugo Chargois - 17 jan. 2010 - v.0.1
# Parses the output of iwlist scan into a table

import sys

# You can add or change the functions to parse the properties of each AP (cell)
# below. They take one argument, the bunch of text describing one cell in iwlist
# scan and return a property of that cell.

def get_name(cell):
    return matching_line(cell,"ESSID:")[1:-1]

def get_quality(cell):
    quality = matching_line(cell,"Quality=").split()[0].split('/')
    return str(int(round(float(quality[0]) / float(quality[1]) * 100))).rjust(3) + " %"

def get_channel(cell):
    return matching_line(cell,"Channel:")

def get_encryption(cell):
    enc=""
    if matching_line(cell,"Encryption key:") == "off":
        enc="Open"
    else:
        for line in cell:
            matching = match(line,"IE:")
            if matching!=None:
                wpa=match(matching,"WPA Version ")
                if wpa!=None:
                    enc="WPA v."+wpa
        if enc=="":
            enc="WEP"
    return enc

def get_address(cell):
    return matching_line(cell,"Address: ")

# Here's a dictionary of rules that will be applied to the description of each
# cell. The key will be the name of the column in the table. The value is a
# function defined above.

rules={"Name":get_name,
       "Quality":get_quality,
       "Channel":get_channel,
       "Encryption":get_encryption,
       "Address":get_address,
       }

# Here you can choose the way of sorting the table. sortby should be a key of
# the dictionary rules.

def sort_cells(cells):
    sortby = "Quality"
    reverse = True
    cells.sort(None, lambda el:el[sortby], reverse)

# You can choose which columns to display here, and most importantly in what order. Of
# course, they must exist as keys in the dict rules.

columns=["Name","Address","Quality","Channel","Encryption"]




# Below here goes the boring stuff. You shouldn't have to edit anything below
# this point

def matching_line(lines, keyword):
    """Returns the first matching line in a list of lines. See match()"""
    for line in lines:
        matching=match(line,keyword)
        if matching!=None:
            return matching
    return None

def match(line,keyword):
    """If the first part of line (modulo blanks) matches keyword,
    returns the end of that line. Otherwise returns None"""
    line=line.lstrip()
    length=len(keyword)
    if line[:length] == keyword:
        return line[length:]
    else:
        return None

def parse_cell(cell):
    """Applies the rules to the bunch of text describing a cell and returns the
    corresponding dictionary"""
    parsed_cell={}
    for key in rules:
        rule=rules[key]
        parsed_cell.update({key:rule(cell)})
    return parsed_cell

def print_table(table):
    widths=map(max,map(lambda l:map(len,l),zip(*table))) #functional magic

    justified_table = []
    for line in table:
        justified_line=[]
        for i,el in enumerate(line):
            justified_line.append(el.ljust(widths[i]+2))
        justified_table.append(justified_line)

    for line in justified_table:
        for el in line:
            print el,
        print

def print_cells(cells):
    table=[columns]
    for cell in cells:
        cell_properties=[]
        for column in columns:
            cell_properties.append(cell[column])
        table.append(cell_properties)
    print_table(table)

def main():
    """Pretty prints the output of iwlist scan into a table"""
    cells=[[]]
    parsed_cells=[]

    for line in sys.stdin:
        cell_line = match(line,"Cell ")
        if cell_line != None:
            cells.append([])
            line = cell_line[-27:]
        cells[-1].append(line.rstrip())

    cells=cells[1:]

    for cell in cells:
        parsed_cells.append(parse_cell(cell))

    sort_cells(parsed_cells)

    print_cells(parsed_cells)

main()

To use, run

iwlist wlan0 scan | iwlistparse.py

where iwlistparse.py is in your PATH. I've aliased iwlist to that aforementioned command so I just run `sudo iwlist` when I want to see the available networks. (If I don't run it with sudo, only the network I'm currently connected to is displayed, rather than all the networks in my vicinity).

Awesome & thank you!  I will definitely give this a whirl when I get home later this evening >:)


{ github | arch }

Offline

#8 2012-04-25 21:32:35

sevenfourk
Member
Registered: 2008-02-21
Posts: 185

Re: Wireless auto-connect

Didn't you think guys, you've been complicating things a bit, doing that using bash scripts, when we got everything under the hood?

I would use WPA_supplicant article.  Worked for me pretty good.


No cause is lost if there is but one fool left to fight for it.

Offline

#9 2012-04-26 14:55:27

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: Wireless auto-connect

sevenfourk wrote:

I would use WPA_supplicant article.  Worked for me pretty good.

I do use wpa_supplicant, but I use wpa_auto to automate starting it up. The script I cited--a Python script--was just a tool to see available networks, not to connect to any tongue.


Registed Linux User 483618

Offline

#10 2012-04-26 15:07:35

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 251

Re: Wireless auto-connect

I use netcfg and wpa_actiond to automatically connect me to the networks I use while on my laptop.

Offline

#11 2012-04-26 19:03:08

sevenfourk
Member
Registered: 2008-02-21
Posts: 185

Re: Wireless auto-connect

Sara wrote:
sevenfourk wrote:

I would use WPA_supplicant article.  Worked for me pretty good.

I do use wpa_supplicant, but I use wpa_auto to automate starting it up. The script I cited--a Python script--was just a tool to see available networks, not to connect to any tongue.

I was actually answering the topic.


No cause is lost if there is but one fool left to fight for it.

Offline

#12 2012-04-27 01:12:12

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: Wireless auto-connect

sevenfourk wrote:

I was actually answering the topic.

My apologies.


Registed Linux User 483618

Offline

#13 2012-04-27 15:15:25

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: Wireless auto-connect

I recently switched from wicd to netcfg. Wicd didn’t automatically reconnect after a connection loss, but netcfg does. Also wicd had a small display bug when connecting. I installed xfce4-wavelan-plugin to have a signal strength indicator in my panel.

The wiki pages make it look like setting netcfg up is complicated, but in reality it is quite easy.

Offline

#14 2012-04-27 22:11:03

sevenfourk
Member
Registered: 2008-02-21
Posts: 185

Re: Wireless auto-connect

Sara wrote:
sevenfourk wrote:

I was actually answering the topic.

My apologies.

I had no intention to force you giving me an apology, I just was sticking to fact.  Now I feel guilty :-)


No cause is lost if there is but one fool left to fight for it.

Offline

#15 2012-04-28 20:09:33

nesneros
Member
From: Arizona
Registered: 2012-04-25
Posts: 20

Re: Wireless auto-connect

Thank you to all of you and your input!  Never intended for this thread to get somewhat off topic by any means.  Thanks again ladies and gents!


{ github | arch }

Offline

#16 2012-04-28 20:33:41

sevenfourk
Member
Registered: 2008-02-21
Posts: 185

Re: Wireless auto-connect

mark as [SOLVED].


No cause is lost if there is but one fool left to fight for it.

Offline

#17 2012-04-29 08:40:18

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,042

Re: Wireless auto-connect

I'll add that the wifi-select tool (mentioned in the netcfg wiki article) is a must for easily adding network profiles if you're moving around a lot.

Last edited by jakobcreutzfeldt (2012-04-29 08:40:50)

Offline

#18 2012-04-29 09:04:34

guelfi
Member
From: /home/guelfi
Registered: 2011-07-01
Posts: 111

Re: Wireless auto-connect

Just wanted to add: The new version of netcfg in [testing] ships with the "wifi-menu" binary, which performs the same task as "wifi-select" does.

Offline

Board footer

Powered by FluxBB