├── example.wifi ├── README.mkd ├── LICENSE └── wifi /example.wifi: -------------------------------------------------------------------------------- 1 | #Put me in $HOME 2 | ProfileName,ESSID,WEPKey,WPAConfLocation, 3 | school,netgear,, 4 | home,linksys,aaaaaaaa,, 5 | work,bluenet,,$HOME/conf/WPA_Passphrase 6 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | This "wifi" script is the culmination of several revisions and 2 | pieces of code. Designed to provide an easy way to handle wifi 3 | connections, it can use either dmenu or arguments to select a 4 | profile. Profiles are stored in csv(comma-seperated value) 5 | format in $HOME/.wifi. An example profile file is included for 6 | reference. The code is very easy to read and is fairly solid, 7 | but as I'm a new coder, there may be areas that are slightly 8 | less elegant than they could be. Suggestions, comments, and 9 | questions are appreciated! 10 | 11 | To use the dmenu interface, execute the script with no args. 12 | If the first argument is the name of a profile, the script 13 | will use the information and attempt to associate to the AP. 14 | If the first argument is not the name of a profile but is 15 | present,the script will try and use that for the name of an AP. 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | 2008, 2009 Ian Daniher < it dot daniher at gmail dot com > 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /wifi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #WIFI Version 2.8 4 | 5 | WIFILE=~/.config/wifi/wifi.csv 6 | WIFACE=wlan0 7 | 8 | #ARG HANDLING 9 | if [ "$1" == "quit" ] 10 | then 11 | exit 0 12 | elif [ "$1" == status ] 13 | then 14 | CUR_ESSID=$(iwconfig $WIFACE|grep ESSID|awk '{print $4}'|sed s/ESSID://) 15 | LINK_QUAL=$(iwconfig $WIFACE|grep Quality|awk '{print $2}'|sed -e "s/.*Quality=//") 16 | CUR_IPADR=$(ifconfig $WIFACE|grep "inet addr"|sed -e "s/.*inet addr://"|sed -e "s/Bcast.*//") 17 | echo $WIFACE: $CUR_ESSID $LINK_QUAL 18 | echo $CUR_IPADR 19 | exit 0 20 | elif [ "$#" == 1 ] 21 | then 22 | PROFLE_NAME=$(cat $WIFILE|grep $1|awk -F, '{print $1}') 23 | else 24 | $0 $(cat $WIFILE|awk -F, '{print $1}'|sed -e 's/ProfileName/quit/'|launcher dmenu -b) 25 | exit 0 26 | fi 27 | 28 | #VARIABLE HANDLING 29 | ESSID_VALUE=$(grep $1 $WIFILE|awk -F, '{print $2}') 30 | WEP_KEY_VAL=$(grep $1 $WIFILE|awk -F, '{print $3}') 31 | WPA_KEY_LOC=$(grep $1 $WIFILE|awk -F, '{print $4}') 32 | 33 | #PROFILE HANDLING 34 | if [ $1 == $PROFLE_NAME ] 35 | then 36 | echo "Profile match!" 37 | ESSID=$ESSID_VALUE 38 | else 39 | echo "Trying $1 for the essid. Are you sure your spelling is correct?" 40 | echo "If you connect to this access point often, add the information in $WIFILE" 41 | ESSID=$1 42 | fi 43 | 44 | #WEP HANDLING 45 | if [ -z $WEP_KEY_VAL ] 46 | then 47 | echo "According to the profile, this AP has no WEP encryption." 48 | else 49 | echo "Poor security is better than no security." 50 | WEP="enc $WEP_KEY_VAL" 51 | fi 52 | 53 | sudo iwconfig $WIFACE mode managed essid $ESSID $WEP 54 | 55 | #WPA HANDLING 56 | if [ -z $WPA_KEY_LOC ] 57 | then 58 | echo "According to the profile, this AP has no WPA encryption." 59 | else 60 | sudo wpa_supplicant -i$WIFACE -c$WPA_KEY_LOC& 61 | fi 62 | 63 | sudo dhclient -r $WIFACE&>/dev/null 64 | sudo dhclient $WIFACE&>/dev/null 65 | 66 | #See LICENSE file for copyright and license details 67 | --------------------------------------------------------------------------------