Created
May 28, 2015 13:54
-
-
Save ke4roh/05f591ee6cf8e053add0 to your computer and use it in GitHub Desktop.
Determine if the given host is localhost
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
#!/bin/bash | |
set -e | |
function isLocalhost { | |
local TEST_IP=$(getent hosts $1 | cut -f1 -d\ | head -1) | |
local ALL_MY_IPS=$(ip addr | grep inet | grep -v link | cut -f2- -de | cut -f2 -d\ | cut -f1 -d/) | |
( echo $ALL_MY_IPS | grep -q $TEST_IP ) && return 0 | |
return 1 | |
} | |
if ( isLocalhost $1 ) ; then | |
echo yes | |
else | |
echo no | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment