LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-22-2009, 04:07 AM   #1
jdkorreck
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 ]
then
echo "usage: wificontrolscript interface"
exit 1
fi
interface=$1
lineno()
{
lineno=1
cat $* |
while read line
do
echo "$lineno:$line"
lineno=$((lineno+1))
done
}

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
then
grep "dhcpcd" ~/temp >~/temp2
sed 's/^ //' ~/temp2 >~/temp
sed 's/ ?.*$//' ~/temp >~/temp2
killval=$(cat ~/temp2)
sudo kill $killval
fi
sudo /sbin/dhcpcd eth1
rm ~/temp
rm ~/temp2
 
Old 04-22-2009, 07:42 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,765
Blog Entries: 27

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Hi,

You can use 'iwconfig';

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

SYNOPSIS
       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

DESCRIPTION
       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.

PARAMETERS
       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
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration