How-to: WPA2 Wireless Configuration Script

For a better overall treatment of wireless networking in Linux check out Wireless Configuration in Linux, but if you just need a fast and easy script to get everything working, here's a quick cheater's way to do so:


if [ $USER != "root" ]; then
    echo "Must be root to run this..."
    ifconfig | grep "Link encap" | grep -v UNSPEC > /tmp/ethlist
    echo "-------------------------------------------------"
    echo "Available interfaces:"
    echo ""
    cat /tmp/ethlist
    echo ""
    echo "-------------------------------------------------"
    read -p "What interface will you use? " -e wlan 
    rm -f /tmp/ethlist
    read -p "What ESSID should I use? " -e wifiname
    read -p "What password should be used? " -e wifipass
    wpa_passphrase $wifiname $wifipass > /tmp/0a9afsn
    wpa_supplicant -Dwext -i$wlan -c/tmp/0a9afsn >/dev/null 2>&1 &
    dhclient $wlan
    while ( [ -e /tmp/0a9afsn ] ); do
        clientcount=`ps -ef | grep -c [w]pa`
        if [ $clientcount = "0" ]; then
            rm -f /tmp/0a9afsn
            exit 0
        sleep 2

And yes, the /tmp/0a9afsn file is just a gibberish choice to make it slightly less obvious where the configuration is being saved. This isn't secure at all, just convenient.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License