Skip to content

Instantly share code, notes, and snippets.

@madpilot
Last active Aug 29, 2015
Embed
What would you like to do?
#!/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