Created
November 16, 2017 22:05
-
-
Save danielscholl/c6e39bcefecb8806fb1aaea7ce12bacf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# get internal IP address | |
# used for outgoing Internet connections | |
resolve() { | |
(gethostip -d $1 || getent ahostsv4 $t | grep RAW | awk '{print $1; exit}') 2>/dev/null | |
} | |
noip() { | |
[ -n "$(echo $1 | tr -d '0-9.\n')" ] | |
} | |
[ -n "$1" ] && t=$1 || t='8.8.8.8' | |
noip $t && t=$(resolve $t) | |
[ -n "$t" ] || { echo Cannot resolve domain $1 >&2; exit 1; } | |
ip route get $t | awk '{print $NF; exit}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment