Connecting to wifi with specified wep key index

Posted by Dan Sosedoff on March 09, 2009

Since i got trouble while connecting to wireless network with given parameters in linux, i tried a lot of ways to get my internet working.

So, the problem is: Windows Network manager have special option – Key index. The index is transmitted with the encrypted message. The receiver then looks-up the key corresponding to the transmitted index and uses it to decrypt the message. But linux (ubuntu) network managers i`ve tried have no key index field, so there is no way to set it up properly with gui. Connection won`t work if index value set to incorrect value.

After giving up to find any useful gui program i wrote small shell script only for one network (because i have no access to router and no chance to improve some security settings):

#!/bin/bash
 
# settings
interface="ath0" # wireless interface, default to wlan0
essid="NETWORK_NAME_HERE"
key="YOUR_KEY_HERE"
index="4" # can be [1..4]
 
# check permission
if [ "$(id -u)" != "0" ]; then
   echo "Run this script under root" 1>&2
   exit 1
fi
 
# show information
echo "Settings:"
echo "-> Interface: $interface"
echo "-> Wifi ESSID: $essid"
echo "-> Key: $key"
echo "-> Key Index: $index"
 
# perform association
ifconfig $interface down
iwconfig $interface essid $essid
iwconfig $interface key $key [$index]
iwconfig $interface key [$index]
ifconfig $interface up
dhclient $interface

Download shell script – http://files.sosedoff.com/9591756c/