Skip to content

Instantly share code, notes, and snippets.

@manisnesan
Forked from ke4roh/islocalhost
Last active August 29, 2015 14:22
Show Gist options
  • Save manisnesan/054fba55e8fe6897ffa3 to your computer and use it in GitHub Desktop.
Save manisnesan/054fba55e8fe6897ffa3 to your computer and use it in GitHub Desktop.
#!/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