Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/bin/bash
IPADDR=""
if [ -f /usr/bin/ec2metadata ]
then
IPADDR=`timeout 1 ec2metadata --public-hostname`
fi
if [ "$IPADDR" = "" ]
then
IPADDR=`curl http://www.jsonip.com 2>/dev/null | egrep -o "[0-9\.]*"`
fi
if [ "$IPADDR" = "" ]
then
IPADDR=`ifconfig | perl -ple 'print $_ if /inet addr/ and $_ =~ s/.*inet addr:((?:\d+\.){3}\d+).*/$1/g ;$_=""' | grep -v ^\s*$ | grep -v 127.0.0.1 | head -n 1`
fi
if [ "$IPADDR" = "" ]
then
IPADDR=`cat /etc/hostname | head -n 1`
fi
echo $IPADDR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.