SHARE
TWEET

Script to force an ip onto wlan0 on RPi

a guest May 6th, 2015 256 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. _MY_IP=`ifconfig | awk '/192.168.111/{print substr($2,6)}'`
  4.  
  5. _NO_ATTEMPTS=0
  6.  
  7. while test -z $_MY_IP && test $_NO_ATTEMPTS -lt 10
  8. do
  9.    _NO_ATTEMPTS=`expr $_NO_ATTEMPTS + 1`
  10.    printf "No IP on wlan0, retrying (%i) ...\n" "$_NO_ATTEMPTS"
  11.    sudo service hostapd stop
  12.    sudo service isc-dhcp-server stop
  13.    sudo ifdown wlan0
  14.    sudo ifup wlan0
  15.    sudo ifconfig wlan0 192.168.111.1
  16.    sudo service hostapd start
  17.    sudo service isc-dhcp-server start
  18.    _MY_IP=`ifconfig | awk '/192.168.111/{print substr($2,6)}'`
  19. done
  20.  
  21. if test -z $_MY_IP
  22. then
  23.    echo "No IP obtained on wlan0 after 10 attempts, giving up."
  24. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top