Using the following script to test accessibility:
Code:
#!/bin/bash
#####################################################################
# wifiConek.sh
# Enter network name and key
# This is a script only for root
##########################################################R###########
# Failed
function usage() {
echo -e "\n\tUsage: `basename $0` \"<essid>\" <key>" \
"\n\t Enter <ascii prefaces>\n"
die
}
# Kill
function die() {
echo -e "\n\t `basename $0` ERROR: $1 <*>\n"
exit 1
}
# Setup
# Get ESSID
if [[ $1 ]]
then echo -e "\n\t>>>Starting by dropping wlan0"
ifconfig wlan0 down # Drop wlan0
sleep 3
dhclient -r wlan0 -q # Drop previous connections
echo -e "\n\t>>>Dropped previous connection(s)"
ifconfig wlan0 up # Activate wlan0
echo -e "\n\t>>>wlan0 activated"
echo -e "\n\tESSID set to $1"
iwconfig wlan0 essid "$1" # Set wlan0 to connect to $1
# Assign Key
if [[ $2 ]]
then echo -e "\n\tKey set to $2"
iwconfig wlan0 key s:"$2" # If exists, set wlan0 use key
fi
# Connect
echo -e "\n\t>>>Set wlan0 to Managed\n"
iwconfig wlan0 mode Managed # Set wlan0 for managed network
echo -e "\n\t>>>Requesting network IP address\n"
dhclient wlan0 # Get IP address
# Success
if [[ $? -eq 0 ]]
then echo -e "\n\n\t>>>Connected to $1!"
exit 0
else die ">>>Failed to connect to $1" # Failure
fi
else usage # No variables
fi
The code seems to connect thru ">>>Connected to" but the iwconfig argues NO.
bash-4.1# iwconfig wlan0
wlan0 IEEE 802.11g ESSID
ff/any Nickname:"poolside"
Mode:Managed Frequency:2.457 GHz Access Point: Not-Associated
Bit Rate:6.5 Mb/s Tx-Power:20 dBm Sensitivity=0/3
RTS thr
ff Fragment thr
ff
Encryption key:4861-7170-7943-6172-5069-7A7A-61 Security mode:restricted
Power Management
ff
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Since I know the AP I was trying to connect with is WPA2 and this script seems to be more for WEP, why did it get thru to >>>Connected to" as tho it was accepting the setup?
Thanx for taking the time to address this!!
bash-4.1$