Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #set -o nounset
- #set -o errexit
- rm .list.tmp 2>/dev/null
- if [[ "$1" == "down" ]]; then
- pkill wpa_supplicant
- ifconfig wlan0 down
- exit
- fi
- if [[ "$1" == "reload" ]]; then
- ifconfig wlan0 down
- pkill wpa_supplicant
- ifconfig wlan0 up
- wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf && dhclient wlan0
- exit
- fi
- ifconfig wlan0 down
- pkill wpa_supplicant
- ifconfig wlan0 up
- iface="wlan0"
- iwlist $iface scan 2>/dev/null > .list.tmp
- eval list=( $(cat .list.tmp | awk -F":" '/ESSID/{print $2}' | nl -w2 -n rz -s "=") )
- #sets prompt
- PS3="Choose wifi connection: "
- #tests for number of wifi connections, exits if none
- if [[ -z "${list[0]}" ]]; then
- clear
- echo "No available wifi connection"
- exit 1
- fi
- #menu of wifi connections
- select item in "${list[@]}"; do
- #sets essid as value for WIFI variable and displays information about the AP
- cell=$(echo $item | awk -F"=" '{print $1}')
- essid=$(echo $item | awk -F"=" '{print $2}')
- sed -ni "/Cell $cell/,/Cell/ p" .list.tmp
- # delete spaces
- echo "$(cat .list.tmp | sed -n 's/^[ \t]*//')"
- #sets channel as value for CHANNEL variable
- channel=$(grep Channel: .list.tmp | sed 's/.*Channel://g')
- #sets pairwise chiphers
- pairwise=$(grep -m 1 Pairwise .list.tmp | sed 's/.* : //g')
- #sets group chiphers
- group=$(grep -m 1 Group .list.tmp | sed 's/.* : //g')
- #test for mode, if mode = master, sets MODE variable to managed
- mode=$(grep Mode .list.tmp | sed 's/.*Mode://g')
- if [[ "$mode" == "Master" ]]; then
- mode="managed"
- else
- clear
- echo "Cannot connect"
- exit
- fi
- #tests for encryption key
- key=$(grep key: .list.tmp | sed 's/.*key://g')
- if [[ $key == "on" ]]; then
- echo -n "Enter encryption key: "
- read key
- fi
- skey=$(wpa_passphrase "$essid" $key 2>/dev/null | sed -n 's/^[ \t]psk=//gp')
- #checks encryption algorithm
- IE=$(grep WPA .list.tmp | sed 's/.*: //g')
- if [[ -n "$IE" ]]; then
- echo "ctrl_interface=/var/run/wpa_supplicant
- ap_scan=1
- network={
- ssid=\"$essid\"
- scan_ssid=0
- proto=WPA RSN
- key_mgmt=WPA-PSK
- pairwise=$pairwise
- group=$group
- psk=$skey
- }" > /etc/wpa_supplicant/wpa_supplicant.conf
- rm .list.tmp 2>/dev/null
- wpa_supplicant -B -Dwext -i $iface -c /etc/wpa_supplicant/wpa_supplicant.conf && dhclient wlan0
- exit
- else
- #sets the wireless configuration for non WPA: essid, channel, mode, key, etc
- iwconfig $iface essid \""$essid"\" channel $channel mode $mode key $key
- #connects to wifi connection
- dhclient $iface
- exit
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement