Skip to content

Instantly share code, notes, and snippets.

@madpilot
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madpilot/d8e28d93a460a75478d8 to your computer and use it in GitHub Desktop.
Save madpilot/d8e28d93a460a75478d8 to your computer and use it in GitHub Desktop.
#!/bin/bash
getMyIP() {
local _ip _myip _line _nl=$'\n'
while IFS=$': \t' read -a _line ;do
[ -z "${_line%inet}" ] &&
_ip=${_line[${#_line[1]}>4?1:2]} &&
[ "${_ip#127.0.0.1}" ] && _myip=$_ip
done< <(LANG=C /sbin/ifconfig)
printf ${1+-v} $1 "%s${_nl:0:$[${#1}>0?0:1]}" $_myip
}
getMyIP IP
if [ -z $1 ]; then
echo "Usage: xip.io domainname"
else
echo "${1}.${IP}.xip.io"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment