pastebin

wifi.txt
  1. #! /bin/bash
  2. #
  3. # wifi          Bring up Wifi networking. Suited for WPA-PSK Wifi networks
  4. #
  5. # P. Kadionik 2006/01/04
  6. #
  7. #
  8.  
  9. # Source function library.
  10. . /etc/init.d/functions
  11. export PATH=/usr/local/sbin:$PATH
  12.  
  13. #IF=$1
  14. # Your wifi interface: ethx, athx, wlanx...
  15. IF=eth1
  16.  
  17. AUTH=NONE
  18. for NET in `iwlist $IF scan 2>/dev/null | grep ESSID | cut -d '"' -f 2`
  19. do
  20.     case $NET in
  21.         "mon_wifi_wpa")       # Place all your WPA Access Point's ssids here like this "1AP"|"2AP")
  22.            AUTH=WPA
  23.            iwconfig $IF essid $NET
  24.            ;;
  25.        "mon_wifi_none")    # Place all OPEN your Access Point's ssids here like this "1AP"|"2AP")
  26.             AUTH=NONE
  27.             iwconfig $IF essid $NET
  28.             ;;
  29.     esac
  30. done
  31.  
  32. case $AUTH in
  33.     NONE)
  34.             dhclient $IF
  35.         ;;
  36.     WPA)
  37.         killall wpa_supplicant 2>/dev/null
  38. # wpa_supplicant is executed for WPA encryption
  39. # Old kernel interface ipw
  40. #        wpa_supplicant -wB -i $IF -c /etc/wpa_supplicant.conf -D ipw
  41. # New kernel interface wext
  42.         wpa_supplicant -wB -W  -i $IF -c /etc/wpa_supplicant.conf -D wext
  43.  
  44.         TIMEOUT=20
  45.         INTERVAL=5
  46.         STATUS=1
  47.         TIME=0
  48.         sleep $INTERVAL
  49.         # Try to authenticate for $TIMEOUT secs
  50.         while [[ $STATUS == 1 && $TIME -lt $TIMEOUT ]]
  51.         do
  52.             wpa_cli status | grep AUTHENTICATED 2> /dev/null
  53.             STATUS=$?
  54.          echo $STATUS
  55.             TIME=$(($TIME + $INTERVAL))
  56.             sleep $INTERVAL
  57.         done
  58.  
  59.         # If authenticated, start dhclient
  60.         if [[ $STATUS -ne 1 ]]
  61.         then
  62. #            dhclient3 -pf /var/run/dhclient.$IF.pid -lf /var/run/dhclient.$IF.leases $IF
  63.             dhclient $IF
  64.         fi
  65.         ;;
  66. esac
  67.  
  68. exit 0
Parsed in 0.043 seconds