LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices

Reply
 
Search this Thread
Old 09-19-2011, 12:01 AM   #1
mladoux
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
Console Wireless Network Utility


I wrote this script a few years back, and just thought I'd share. It's pretty straight forward, but I recommend you adjust the settings to fit your card before using it. It supports unencrypted, WEP, and WPA networks. It of course requires the corresponding wireless utilities to be installed on your system already. It saves all configs in your /etc directory so that it can remember network settings so that it doesn't have to prompt you all the time. Anyway, enjoy! Oh, the email address in the comments isn't valid anymore. If you need to contact me, just send me a private message and I'll get back to you.

Code:
#!/bin/bash

################################################################
## PROJECT #####################################################
################################################################
## Date    : 09/21/2007                                       ##
## Version : 1.3                                              ##
## Program : wlassist                                         ##
## Author  : Mark A. LaDoux                                   ##
## Website :http://www.haktstudios.com                       ##
## E-Mail  : t0nedef@haktstudios.com                          ##
################################################################
## 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
 
Old 09-19-2011, 07:34 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Nice to have, definitely saving to my "cool-scripts-I-found-to-use" directory
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
A linux utility to dump HDD sectors to console. stf92 Linux - Software 5 12-11-2010 04:08 PM
Utility to take screenshots on console while graphics is displayed kushalkoolwal Linux - Software 4 01-02-2009 10:15 AM
Best Wireless Utility sKiBa Linux - Newbie 3 11-15-2006 04:03 PM
Wireless Monitor Utility majoritywhip Linux - Wireless Networking 9 11-10-2004 11:42 AM
knoppix wireless connection utility anonymoushacker Linux - Wireless Networking 2 03-11-2004 12:54 PM


All times are GMT -5. The time now is 05:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration