Advertisement
josephxsxn

wifi-connect.sh

Jun 30th, 2017
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.20 KB | None | 0 0
  1. #!/bin/bash
  2. #Set the SSID you want to reconnect to when found
  3. timstim=$(date -u)
  4. ssid="AD-INFRA-E1000"
  5. interface="wlan0"
  6. string=$(ifconfig $interface| grep "inet addr:")
  7. if [[ $string == *"inet addr:"* ]]; then
  8.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"CONNECTED\"}]}"
  9. else
  10.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"DISCONNECTED\"}]}"
  11.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"SCANNING\"}]}"
  12.     ssidlist=$(sudo iwlist $interface scan | grep ESSID)
  13.     if [[ "$ssidlist" =~ "$ssid" ]]; then
  14.         sudo ifup --force $interface
  15.         sleep 10
  16.         string=$(ifconfig $interface | grep "inet addr:")
  17.         if [[ $string == *"inet addr:"* ]]; then
  18.             echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"RECONNECTED\"}]}"
  19.         else
  20.             echo  "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"UNKNOWN_ISSUE_RECONNECTING\"}]}"
  21.         fi
  22.     else
  23.         echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"SSID_NOT_FOUND\"}]}"
  24.         echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"DISCONNECTED\"}]}"
  25.     fi
  26. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement