Advertisement
gluk47

wifi connection script

Oct 4th, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ok () {
  4.   echo -e '\e[32;1m[  OK  ]\e[0m'
  5. }
  6.  
  7. fail () {
  8.   echo -e '\e31;1m[ Fail ]\e[0m'
  9. }
  10.  
  11. connect () {
  12.   echo -n 'Resetting interface... '
  13.   ifconfig wlan0 down
  14.   sleep 3
  15.   ifconfig wlan0 up
  16.   ok
  17.   echo -n 'Connecting... '
  18.   wpa_supplicant -Dwext -iwlan0 -B -c /home/gluk47/wpa_supplicant.conf || { fail; return 1; }
  19.   ok
  20.  
  21.   echo -n 'Running dhclient... '
  22.   if dhclient wlan0; then
  23.     ok
  24.   else
  25.     fail
  26.     return 1
  27.   fi
  28. }
  29.  
  30. connected () {
  31.   ping -c1 8.8.8.8 &>/dev/null
  32. }
  33.  
  34. setup_network () {
  35.   date
  36.   connected && { echo 'Already connected'; return 0; }
  37.   connect
  38.   connected && { echo Connected; return 0; }
  39.   echo -n 'Reloading wifi module... '
  40.   rmmod iwldvm
  41.   rmmod iwlwifi
  42.   sleep 1
  43.   modprobe iwlwifi
  44.   ok
  45.   connect
  46. }
  47.  
  48. while :; do
  49.         connected || setup_network
  50.         sleep 5
  51. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement