|
Nico and Co. Exutoire, zone libre de Nicolas Barcet
|
| connexion ssl |
Navigationlinux tricks [en]RSS Général
|
Automatically configure your wlan settings
Nicolas 01/06/2005 - 10:07
I use the following script to easily configure my wlan connexions. It can be used in 3 ways : 1 - no parameters : it is going to detect automatically available wlan and connect me automatically to the first know one as found in /etc/sysconfig/network/wlan/. 2 - eth0 : deactivates wlan0 and activate eth0 3 - conf name : it directly applies a conf whose name is found in /etc/sysconfig/network/wlan/ I have added to my K menu the following 3 entries : I use it on Suse Linux Pro 9.3 with great success...
#!/bin/bash
#
# Usage: iwautoconfig [eth0|wlanconfname]
#
# Automatically configures wlan based on the findings of
# known networks compared to available networks.
# Use param eth0 to disable your wlan interface and
# enable eth0. If you specify a wlanconfname, it must be
# the name of a valid conf file that will be used without
# searching for it.
#
# You need to have a dir specified by WLAN that contains
# various valid config file. Name of the file should be
# the essid of the network it applies to. To add a new
# network, configure it using yast, then copy the file
# /etc/sysconfig/network/ifcfg-{interface} to the wlan dir.
# If no network seems to match, the config file named
# 'default' will be used.
#
# Note that the user executing this command must be
# configured as a sudoer...
#
# Author : nicolas@barcet.com
##### CONSTANTS :
# WLAN : Specify the dir where valid config are stored
WLAN=/etc/sysconfig/network/wlan/
# NETWORK : Place here the root name of the config file
NETWORK=/etc/sysconfig/network/ifcfg-
# INTERFACE : name of the interface to be configured
INTERFACE=wlan0
CONFDIR=$(sudo ls $WLAN) # Get list of valid configurations
ESSID=""
if [[ $1 != "eth0" ]]; then
sudo /sbin/ifdown eth0 &> /dev/null
sudo /usr/sbin/iwlist wlan0 scanning > /tmp/iwlist.tmp # Retrieve list of advertised wlan
if [[ $1 != "" ]]; then
ESSID=$1
else
# search in list of available conf a net that is available
for NN in $CONFDIR ; do
if [[ `cat /tmp/iwlist.tmp | grep $NN` != "" ]]; then
ESSID=$NN
break;
fi;
done
fi;
# if we did not find any valid net, use default
if [[ $ESSID == "" ]]; then
ESSID=default
fi;
#copy the good conf to make is active
sudo cp $WLAN$ESSID $NETWORK$INTERFACE
#set iwconfig appropriately
source $WLAN$ESSID # Read the var values from the file
if [[ $WIRELESS_AUTH_MODE == open ]]; then
WIRELESS_KEY_0='off'
fi;
sudo iwconfig $INTERFACE rate $WIRELESS_BITRATE
sudo iwconfig $INTERFACE mode $WIRELESS_MODE
sudo iwconfig $INTERFACE enc $WIRELESS_KEY_0
sudo iwconfig $INTERFACE essid $WIRELESS_ESSID
sudo iwconfig $INTERFACE commit
#force full reload if conf has changed from before
if [[ $ESSID != `iwgetid wlan0 -s -r` ]]; then
echo Found : $WIRELESS_ESSID - Forcing conf reload...
sudo /sbin/ifdown $INTERFACE &> /dev/null
sudo /sbin/ifup $INTERFACE &> /dev/null
else
echo Found : $WIRELESS_ESSID - No Change
sudo /sbin/ifup $INTERFACE &> /dev/null
fi;
#set iwconfig again !!! Just to make sure
sudo iwconfig $INTERFACE rate $WIRELESS_BITRATE
sudo iwconfig $INTERFACE mode $WIRELESS_MODE
sudo iwconfig $INTERFACE enc $WIRELESS_KEY_0
sudo iwconfig $INTERFACE essid $WIRELESS_ESSID
sudo iwconfig $INTERFACE commit
sleep 10
#Are we now really connected ?
NEWESSID=`iwgetid $INTERFACE -s -r`
if [[ $NEWESSID == "" ]]; then
echo ERROR !! Not connected to anything...
echo 'Available nets follows :'
grep ESSID /tmp/iwlist.tmp
kdialog --passivepopup "ERROR !! Not connected to anything..." 30 &> /dev/null &
else
echo ---------------------------------------
echo Now connected to $NEWESSID
echo ---------------------------------------
kdialog --passivepopup "Now connected to $NEWESSID" 30 &> /dev/null &
fi;
rm /tmp/iwlist.tmp
else
#We want to switch back to eth0
sudo /sbin/ifdown $INTERFACE &> /dev/null
sudo /sbin/ifup eth0 &> /dev/null
fi;
Technorati Tags: |
Trucs et astuces
Pour être notifié automatiquement des derniers changements sur ce site, inscrivez vous...
ConnexionTags
électronique
april
brevets
démocratie
dadvsi
dgme
divers
drm
europe
ffii
fiction
filter
filtrage
france
IAM
informatique
internet
interopérabilité
ipred2
itunes
kids
kvm
législation
lemeur
liberté
libertyalliance
linux
linuxworld08
logiciel libre
machine-a-voter
mandriva
monde
moratoire
OOXML
openID
oscon08
pétition
p2p
Paquet telecom
parents
partage
pme
politique
présidentielle
presidentielles
presse
revendication
RFID
sarkozy
schiboleth
server
solutionslinux
sondage ubuntu server linux
syndicat
téléchargement
technique
ubuntu
virtualization
vote
[en]
Blogue récents
RSS Linux
Recherche |
Commentaires récents
il y a 24 weeks 6 days
il y a 26 weeks 1 jour
il y a 26 weeks 2 days
il y a 1 année 14 weeks
il y a 1 année 29 weeks
il y a 1 année 29 weeks
il y a 1 année 34 weeks
il y a 1 année 35 weeks
il y a 1 année 35 weeks
il y a 1 année 36 weeks