Last active
December 14, 2015 22:09
-
-
Save paulbdavis/5156219 to your computer and use it in GitHub Desktop.
Script to get your external ip, with caching (use a cron job to remove the file periodically, or whatever)
This file contains hidden or 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
#!/usr/bin/env bash | |
if [ "$1" = "-r" ] | |
then | |
rm $HOME/.externalip | |
exit 0; | |
fi | |
cacheFile="$HOME/.externalip" | |
if [ ! -f "$cacheFile" ] || [ ! "$(cat $cacheFile)" ] | |
then | |
wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>' > "$cacheFile" | |
fi | |
echo $(cat "$cacheFile") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment