Skip to content

Instantly share code, notes, and snippets.

@rinx
Last active August 29, 2015 13:57
Show Gist options
  • Save rinx/9885825 to your computer and use it in GitHub Desktop.
Save rinx/9885825 to your computer and use it in GitHub Desktop.
#!/bin/sh
CMDNAME=`basename $0`
while getopts glt OPT
do
case $OPT in
"g" ) FLG_G="TRUE" ;;
"l" ) FLG_L="TRUE" ;;
"t" ) FLG_T="TRUE" ;;
* ) echo "Usage: $CMDNAME [-g] [-l] [-t]" 1>&2
exit 1 ;;
esac
done
getlocalipaddr(){
local=`ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2;}' | cut -d: -f2`
if [ "$local" = "" ]; then
exit 1
else
echo "$1$local"
fi
}
getglobalipaddr(){
global=`curl -s http://ifconfig.me/ip`
if [ "$global" = "" ]; then
exit 1
else
echo "$1$global"
fi
}
if [ "$FLG_T" = "TRUE" ]; then
sec=`date +"%S"`
if [ $sec -ge 30 ]; then
getglobalipaddr ' | g:'
else
getlocalipaddr ' | l:'
fi
elif [ "$FLG_L" = "TRUE" ]; then
getlocalipaddr
elif [ "$FLG_G" = "TRUE" ]; then
getglobalipaddr
else
getlocalipaddr 'local: '
getglobalipaddr 'global: '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment