Created
May 15, 2017 17:20
-
-
Save schcriher/e6e3280efc55af5be6ff1b4f43ebeffc to your computer and use it in GitHub Desktop.
Returns public IP, querying a URL every few minutes at most. If the IP is queried very fast, the cached IP is returned
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
#!/bin/bash | |
minute=5 | |
cache=/tmp/public-ip-cached | |
if [[ ! -f $cache || $(echo "$(stat -c %Y $cache) + $minute * 60 < $(date +%s)" | bc) -eq 1 ]];then | |
wget http://ipinfo.io/ip -qO - > $cache | |
fi | |
cat $cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment