From c09815fccc50b9cc65908baf8d02fbb1825a540d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 13 Dec 2017 23:55:18 -0500 Subject: [PATCH] Add bin/myip --- bin/myip | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 bin/myip diff --git a/bin/myip b/bin/myip new file mode 100755 index 00000000..e0d39758 --- /dev/null +++ b/bin/myip @@ -0,0 +1,21 @@ +#!/usr/bin/env zsh +# Echos your local or WAN IP + +if [[ $1 == -w ]]; then + wan=1 + shift +fi + +if [[ $wan ]]; then + dig +short myip.opendns.com @resolver1.opendns.com +else + IF=$(netstat -rn | awk '/^0.0.0.0/ {thif=substr($0,74,10); print thif;} /^default.*UG/ {thif=substr($0,65,10); print thif;}') + if _is_callable ifconfig; then + ifconfig ${NET_IF} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' + elif _is_callable ip; then + ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/' + else + >&2 echo "No easy way to grab your IP" + exit 1 + fi +fi