Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-22-2009, 05:07 AM   #1
LQ Newbie
Registered: Mar 2009
Location: Michigan / United States
Distribution: Debian, MacOSX
Posts: 2

Rep: Reputation: 0
Writing a script to attach to a WiFi Network

Ok the following source code is a work in progress and still needs many improvements. What I'm wondering though is if anyone knows a command line tool I could use that would identify if the essids were open, wep, or wpa.

#! /bin/bash

# Jeremiah Korreck
# Script to display wi-fi access points and then connect to one
# It only works for open access points at the moment

if [ $# -ne 1 ]
echo "usage: wificontrolscript interface"
exit 1
cat $* |
while read line
echo "$lineno:$line"

sudo iwlist scan 2>/dev/null | grep ESSID > temp
sed 's/^ *//' ~/temp >~/temp2
lineno ~/temp2 >~/temp
cut -f1,3 -d: ~/temp >~/temp2
echo "Available Access Points"
cat ~/temp2
echo "Enter the number of the Access Point to attach to:"
read answer
grep "^$answer" ~/temp2 >~/temp
cut -f2 -d: ~/temp >~/temp2
sed 's/^"//' ~/temp2>~/temp
sed 's/"$//' ~/temp>~/temp2
myessid=$(cat ~/temp2)
sudo iwconfig $interface 'essid' $myessid
ps -e > ~/temp
if grep "dhcpcd" ~/temp>/dev/null
grep "dhcpcd" ~/temp >~/temp2
sed 's/^ //' ~/temp2 >~/temp
sed 's/ ?.*$//' ~/temp >~/temp2
killval=$(cat ~/temp2)
sudo kill $killval
sudo /sbin/dhcpcd eth1
rm ~/temp
rm ~/temp2
Old 04-22-2009, 08:42 AM   #2
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,917
Blog Entries: 28

Rep: Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208Reputation: 2208

You can use 'iwconfig';

excerpt from 'man iwconfig';
  iwconfig - configure a wireless network interface

       iwconfig [interface]
       iwconfig interface [essid X] [nwid N] [mode M] [freq F]
                          [channel C][sens S ][ap A ][nick NN ]
                          [rate R] [rts RT] [frag FT] [txpower T]
                          [enc E] [key K] [power P] [retry R]
                          [modu M] [commit]
       iwconfig --help
       iwconfig --version

       Iwconfig  is  similar  to ifconfig(8), but is dedicated to the wireless
       interfaces. It is used to set the parameters of the  network  interface
       which  are  specific  to the wireless operation (for example : the fre-
       quency).  Iwconfig may also be used to display  those  parameters,  and
       the wireless statistics (extracted from /proc/net/wireless).
 All  these  parameters and statistics are device dependent. Each driver
       will provide only some of them depending on hardware support,  and  the
       range of values may change. Please refer to the man page of each device
       for details.

       essid  Set the ESSID (or Network Name - in some products it may also be
              called Domain ID). The ESSID is used to identify cells which are
              part of the same virtual network.
              As opposed to the AP Address or NWID which define a single cell,
              the  ESSID  defines  a group of cells connected via repeaters or
              infrastructure, where the user may roam transparently.
              With some cards, you  may  disable  the  ESSID  checking  (ESSID
              promiscuous) with off or any (and on to reenable it).
              If  the  ESSID  of  your  network is one of the special keywords
              (off, on or any), you should use -- to escape it.
              Examples :
                   iwconfig eth0 essid any


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
FC6: Attach SL Network Drive ericcarlson Fedora 1 03-31-2007 09:41 PM
problems with script writing to network share neocookie Linux - Newbie 2 03-22-2007 06:44 AM
Linux does not attach to network (route?) windsurfer Linux - Networking 9 01-08-2007 04:05 PM
Need Help Writing a Network Script gauge73 Linux - Networking 1 12-15-2003 05:35 PM
How do I zip and attach the output data of a grep | awk | mail shell script? 360 Programming 1 05-08-2002 09:26 AM > Forums > Linux Forums > Linux - Newbie

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

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