Created
February 26, 2018 07:47
-
-
Save klang/d00cf3f5b649d2356907ef156a3c468f to your computer and use it in GitHub Desktop.
resolve dns via local hosts file
This file contains 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
function resolve { | |
hostfile=~/.hosts | |
if [[ -f "$hostfile" ]]; then | |
for arg in $(seq 1 $#); do | |
if [[ "${!arg:0:1}" != "-" ]]; then | |
ip=$(sed -n -e "/^\s*\(\#.*\|\)$/d" -e "/\<${!arg}\>/{s;^\s*\(\S*\)\s*.*$;\1;p;q}" "$hostfile") | |
if [[ -n "$ip" ]]; then | |
command "${FUNCNAME[1]}" "${@:1:$(($arg-1))}" "$ip" "${@:$(($arg+1)):$#}" | |
return | |
fi | |
fi | |
done | |
fi | |
command "${FUNCNAME[1]}" "$@" | |
} | |
function ping { | |
resolve "$@" | |
} | |
function traceroute { | |
resolve "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment