LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-19-2005, 12:42 PM   #1
miguelmmg
LQ Newbie
 
Registered: Nov 2003
Location: México, D.F.
Distribution: Ubuntu
Posts: 9

Rep: Reputation: 0
Lightbulb Wireless LAN connection script


Hi everyone.
I've made a little shell script to manage my wireless lan connections. Please give me your suggestions and enhancements. Enjoy it!

Code:
#!/bin/sh
# rc.wirelesslan
# Wireless LAN connection script
#
# 20050718 v1.0
# Miguel Melendez (miguelmmg at yahoo com mx)
#
# TO-DO:
# * Connect to any ESSID without WEP
# * Connect ESSID by priority
#
# Aditional notes:
# My english is terrible, forgive my mistakes.
# The original script is in spanish if you want it.
# El script original este en idioma espaniol por si alguien lo desea.

# Wireless LAN interface
IF="wlan0"
DHCPHOSTNAME="movil"

# WLAN Card Options
MODE="Managed"

# WEP keys. Put your own key's like: KEY_<your known ESSID>="wepkey"
# Note: These are not real ESSID's and WEP keys. :D 
KEY_2WIRE222="2EA9180813"
KEY_wLAN2="FE14024FA2"
KEY_home="473AC30230"
KEY_Work="D3ACCC8579"

case "$1" in
    'stop')
    if (/sbin/ifconfig | grep -q -w $IF); then
        /sbin/dhcpcd -k $IF
        /sbin/iwconfig $IF essid any
    fi
    ;;

    'start')
    # Array and numbrer of available ESSIDs
    ESSIDs=($(/sbin/iwlist $IF scanning | grep ESSID | cut -d\" -f2))
    nESSID=${#ESSIDs[@]}

    if (/sbin/ifconfig | grep -q -w $IF); then
        echo "A Wireless LAN conection is already active in $IF"
        exit
    fi

    if (( nESSID == 0 )); then
        echo "No ESSID's available in this place"
    else
        # Try to make a link to available ESSID's
        for (( i=0; i < nESSID; i++)) do
            echo -n "Wireless LAN ${ESSIDs[$i]}: "
            # Search ESSID's WEP key
            keyESSID="KEY_${ESSIDs[$i]}"
            WEPKEY=${!keyESSID}
            if [ -z "$WEPKEY" ]; then
                echo "no WEP key configured"
            else
                if [ -z "$WIRELESSLAN" ]; then
                    /sbin/iwconfig $IF mode ${MODE}
                    /sbin/iwconfig $IF essid ${ESSIDs[$i]}
                    /sbin/iwconfig $IF encryption ${WEPKEY}
                    # Little delay waiting link completed
                    sleep 5
                    if (/sbin/iwconfig $IF | grep -q ${ESSIDs[$i]}); then
                        WIRELESSLAN="OK"
                        echo -n "linked to AP"
                        if (/sbin/dhcpcd -h $DHCPHOSTNAME $IF); then
                            echo " and IP address assigned"
                        else
                            echo " but no response from DHCP server"
                        fi
                    else
                        echo "error"
                    fi
                else
                    echo "available"
                fi
            fi
        done
    fi
    ;;

    *)
    echo "Usage: $0 start|stop"
esac

Last edited by miguelmmg; 07-19-2005 at 02:45 PM.
 
Old 07-19-2005, 12:49 PM   #2
Namaseit
Member
 
Registered: Dec 2003
Distribution: Slackware
Posts: 325

Rep: Reputation: 30
One suggestion. If those are the *real* keys for the WEP on your wireless you might want to change that

Last edited by Namaseit; 07-19-2005 at 12:53 PM.
 
Old 07-19-2005, 12:56 PM   #3
miguelmmg
LQ Newbie
 
Registered: Nov 2003
Location: México, D.F.
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: 0
Of course, they are not real. Only examples
Thanks for your suggestion, I've added a note indicating that.
 
Old 07-19-2005, 01:03 PM   #4
Namaseit
Member
 
Registered: Dec 2003
Distribution: Slackware
Posts: 325

Rep: Reputation: 30
That's good
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Compex (NP16A) wireless router with USB wireless LAN atlantis8 Linux - Wireless Networking 1 09-19-2008 08:11 PM
Dell Wireless Lan 1370 - No connection max_power83 Linux - Wireless Networking 3 01-11-2006 11:33 PM
wireless on Linux dying when I bring another wireless device in the LAN sal_paradise42 Linux - Wireless Networking 5 11-14-2004 03:38 AM
connecting to the internet via wireless through Intel PRo/Wireless LAN 2100 3B Mini P k_wjss Linux - Newbie 1 09-28-2004 05:00 PM
My Configurable Wireless Connection Script miasmatic Linux - Wireless Networking 0 02-18-2004 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration