Last active
November 14, 2017 08:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chmod +x wifiremember.sh, then | |
# type `crontab -e` and add this line : | |
* * * * * $HOME/wifiremember/wifiremember.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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