SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.