Skip to content

Instantly share code, notes, and snippets.

@kairyou
Last active August 29, 2015 14:11
Show Gist options
  • Save kairyou/eb8e4b9209e210dd4f7c to your computer and use it in GitHub Desktop.
Save kairyou/eb8e4b9209e210dd4f7c to your computer and use it in GitHub Desktop.
bash get ip
#!/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