Last active
August 29, 2015 14:11
-
-
Save kairyou/eb8e4b9209e210dd4f7c to your computer and use it in GitHub Desktop.
bash get ip
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 | |
# bash get ip | |
declare -a api=("ifcfg.me" "ident.me" "tnx.nl/ip" "ip.appspot.com" "ifconfig.me" "curlmyip.com"); | |
IP=$(curl -s --retry 3 --retry-delay 10 ${api[0]}); | |
while [ -z "$IP" ] # If no IP | |
do | |
sleep 0.5; | |
random=$(( RANDOM % ${#api[@]} )); | |
IP=$(curl -s --retry 3 --retry-delay 10 ${api[$random]}); | |
done | |
echo "IP: $IP" | |
echo "----- set hostname:" | |
echo "cat /proc/sys/kernel/hostname >> ~/.hostname_bak; sudo hostname $IP"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment