This is the second script ive ever written and ive only been on linux for about a week so please no bashing the code as this was completed as a learning experience. I have added support for WEP as my other script only worked on WPA/WPA2.

All credit goes to ptrakk without his post on connecting to wpa's i wouldn't have known how to make this.

To run this stop any scanning, then save the code to a text file and name it connect.sh, place it on the desktop, open bash and do "cd Desktop" watch out for the D , then type "sh connect.sh" and follow the directions. When your all finished run dhclient wlan0 "or whatever your interface is" to set up dhcp.

This WILL work on BT4 and your ALFA card as thats what im using.

UPDATED:You can now connect to WPA/WPA2's that have a space in them. Just type the ssid "Like This" ... Also its is sensitive to Upper/lower case so make sure you get it correct.



#start
rm wpa.conf
rm wep.conf
killall NetworkManager
killall knetworkmanager
killall wpa_supplicant
killall dhclient
clear
echo "Enter the interface name (eth1, wlan0, rausb0, etc)"
read IFACE
clear
echo "it takes a little bit"
airmon-ng stop wlan0
airmon-ng stop mon0
clear
echo "dont worry its not frozen it just takes a moment"
echo "about 30 seconds so be patient"
echo "and dont hit enter"
ifconfig $IFACE up
wait 20
clear
echo "Is this WEP?"
echo "Type yes or no"
read YN
clear

if [ "$YN" != "no" ]
then
echo "Enter the WEP's SSID!"
read SSIDWEP
clear
echo 'network={ \n ssid="'$SSIDWEP'" \n key_mgmt=NONE \n wep_key0="fakeauth" \n }' > wep.conf
wpa_supplicant -c wep.conf -i $IFACE -Dwext -B
echo "Enter the WEP key!"
read WEPKEY
iwconfig $IFACE key $WEPKEY
clear
echo "Now just dhclient your interface or write iptabels"
fi

if [ "$YN" != "yes" ]
then
echo "Enter the WPA/WPA2's SSID!"
read SSIDWPA
clear
echo "Enter the WPA/WPA2 key!"
read WPAKEY
clear
F=">"
echo wpa_passphrase $SSIDWPA $WPAKEY $F wpa.conf > wpas.sh
echo iwconfig $IFACE essid $SSIDWPA > iw.sh
clear
sh wpas.sh
sh iw.sh
rm wpas.sh
rm iw.sh
clear
wpa_supplicant -B -Dwext -i $IFACE -c wpa.conf
clear
echo "Now just dhclient your interface or write iptabels"
fi
#end
Comment if you like / use it and i might make some other nifty tools. Also if someone could tell me why i needed to reverse the " if [ "$YN" != "no" ] " part im all ears.