Created
September 12, 2016 06:20
-
-
Save piaoger/7a0d4c9013f8665402af5ed3df6f0788 to your computer and use it in GitHub Desktop.
get-public-ipv4.sh
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
# get public ipv4 | |
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html | |
# http://stackoverflow.com/questions/14594151/methods-to-detect-public-ip-address-in-bash | |
AMI_ID=$(curl --connect-timeout 5 "http://169.254.169.254/latest/meta-data/ami-id") | |
if [[ $AMI_ID == ami-* ]] ; | |
then | |
IPV4=$(curl --connect-timeout 5 "http://169.254.169.254/latest/meta-data/public-ipv4") | |
else | |
IPV4=$(curl --connect-timeout 5 "http://ipinfo.io/ip") | |
fi | |
echo "public-ivp4: $IPV4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment