Skip to content

Instantly share code, notes, and snippets.

@mastef
Last active November 14, 2017 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastef/d915a9489b1baf86b9194189d066e61b to your computer and use it in GitHub Desktop.
Save mastef/d915a9489b1baf86b9194189d066e61b to your computer and use it in GitHub Desktop.
Remember wifi names and ip addresses - in case the router's dhcp stops working you can still reconnect to it
# chmod +x wifiremember.sh, then
# type `crontab -e` and add this line :
* * * * * $HOME/wifiremember/wifiremember.sh
# create the wifiremember directory in the user's home directory if it doesn't exist yet
mkdir -p $HOME/wifiremember
# the .txt file we want to save to
FILE=$HOME/wifiremember/wifinetworks.txt
# read current wifi name
WIFINAME="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}')"
# read current ip from en0
IPINFO="$(/sbin/ifconfig en0|/usr/bin/grep inet| /usr/bin/sed -e 's/^[[:space:]]*//')"
# add the result to one line
LINE="Wifi: "$WIFINAME" IP: "$IPINFO
#only add line to wifinetworks.txt if it doesn't exist already
/usr/bin/grep -qF "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment