/ Published in: Bash
URL: http://mark.haktstudios.com
A simple command line wireless network manager written in Bash for Linux that I wrote a while ago. This is one of those scripts that I've used forever because it simply just works. Requires Linux wireless utilities, Bash, WPA Utilities, and a some minor system specific configurations. The default settings should work well on MOST systems, however, on some systems you will need to change the wireless driver used.
Expand |
Embed | Plain Text
#!/bin/bash ################################################################ ## PROJECT ##################################################### ################################################################ ## Date : 09/21/2007 ## ## Version : 1.3 ## ## Program : wlassist ## ## Author : Mark A. LaDoux ## ## Website :http://www.haktstudios.com ## ## E-Mail : [email protected] ## ################################################################ ## DESCRIPTION ################################################# ################################################################ ## Console application to simplify the maintainence of ## ## wireless network settings. It stores configurations and ## ## recalls them when requested. It is capable of handling ## ## unencrypted, WEP, and WPA encrypted networks. ## ################################################################ ## DEPENDANCIES ################################################ ################################################################ ## Wireless capable device ## ## bash 2.x or better ## ## linux wireless utils (for configuring wireless card) ## ## wpa_supplicant (for accessing wpa networks) ## ## permissions to modify network settings ## ################################################################ ## COPYRIGHT ################################################### ################################################################ ## ©2007 Hakt Studios. http://www.haktstudios.com ## ## ## ## This program is free software; you can redistribute it ## ## and/or modify it under the terms of the GNU General ## ## Public License as published by the Free Software ## ## Foundation; either version 3 of the License, or (at your ## ## option) any later version. ## ## ## ## This program is distributed in the hope that it will be ## ## useful, but WITHOUT ANY WARRANTY; without even the implied ## ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ## ## PURPOSE. See the GNU General Public License for more ## ## details. ## ## ## ## You should have received a copy of the GNU General Public ## ## License along with this program. If not, see ## ## <http://www.gnu.org/licenses/>. ## ################################################################ ################################################################ ## Ok to start we are going to define a couple of things ## ## please adjust thes variables to match your hardware ## DRIVER=wext ## This is the driver to use for wpa_supplicant ## IFACE=wlan0 ## this is the network interface to use ## ################################################################ ################################################################ ## DO EDIT ANYTHING BELOW THIS POINT ## ################################################################ RUID=0 # root uid WDIR=/etc/wlassist # where settings are stored # Ensure that search path is defined - sometimes when using su or # sudo it doesn't get set properly, and that causes errors with # the script. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH ################################################################ ## ERROR CODES ## ################################################################ E_NR=65 # not root E_IO=66 # invalid option E_NF=67 # Not Found E_UC=68 # User Canceled ### # Ask user if they would like to proceed to the next step function CONTINUE(){ echo "Would you like to continue? (Y/n)" read YESNO if [ "$YESNO" == "N" ] || [ "$YESNO" == "n" ] then echo "Terminating program per user request..." exit "$E_UC" fi } ### # Select Wireless Encryption Method function ENCRYPT(){ echo "What encryption does $ESSID use?" echo "" echo "1) none" echo "2) WEP" echo "3) WPA" CFILE=$WFILE.conf read CRYPT case "$CRYPT" in ## No Encryption "1" ) echo "You have chosen to not use encryption..." CONTINUE echo "Saving settings...." echo "#!/bin/bash" >> "$WFILE" echo "iwconfig $IFACE essid $ESSID" >> "$WFILE" echo "dhclient $IFACE" >> "$WFILE" chmod +x "$WFILE" echo "Initializing connection" "$WFILE" exit 0 ;; ## WEP Encryption "2" ) echo "You have chosen to use WEP..." CONTINUE echo "Ok, now I would like to collect some info from you." echo "What is your WEP Key?" read KEY echo "Please double check the key for errors before continuing." echo "$KEY" CONTINUE echo "Saving settings..." echo "#!/bin/bash" >> "$WFILE" echo "iwconfig $IFACE essid $ESSID key $KEY" >> "$WFILE" echo "dhclient $IFACE" >> "$WFILE" chmod +x $WFILE echo "Initializing connection" "$WFILE" exit 0 ;; ## WPA-PSK Encryption "3") echo "You have chosen to use WPA..." CONTINUE echo "Okay, now I would like to collect some info from you" echo "What is your WPA passphrase?" read PSK echo "Please double check your passphrase for errors before continuing." echo "$PSK" CONTINUE echo "Saving settings..." ## begin conf file echo "network={" >> "$CFILE" echo " ssid=\"$ESSID\"" >> "$CFILE" echo " psk=\"$PSK\"" >> "$CFILE" echo "}" >> "$CFILE" ## begin script file echo "#!/bin/bash" >> $WFILE echo "wpa_supplicant -D$DRIVER -i$IFACE -c$CFILE &" >> "$WFILE" echo "dhclient $IFACE" >> "$WFILE" chmod +x $WFILE echo "Initializing connection" "$WFILE" exit 0 ;; ## Invalid Selection * ) echo "Invalid option, exiting program..." exit "$E_IO" ;; esac } ## Program Begins Here ## # Check to make sure user has permission to modify network settings if [ "$RUID" != "$UID" ] then echo "I'm sorry, but you don't seem to have proper permission" echo "to perform this action" exit "$E_NR" fi # Check for configuration directory # if it doesn't exist, create it if [ ! -e "$WDIR" ] then mkdir "$WDIR" fi # Fix for systems where the wireless is down by default ifconfig "$IFACE" up # Ask if user wants to scan echo "Would you like to scan available networks? (y|N)" read NOYES if [ "$NOYES" == "Y" ] || [ "$NOYES" == "y" ] then iwlist "$IFACE" scan | less fi # Get the Network Name echo "Which network would you like to connect to today?" read ESSID WFILE=$WDIR/$ESSID # See if configuration already exists for this network # if it doesn't, proceed to creating a new one if [ ! -e "$WFILE" ] then echo "No configuration for $ESSID currently exists!" CONTINUE ENCRYPT fi # Execute network configuration $WFILE exit 0
You need to login to post a comment.
