Skip to content

Commit

Permalink
fix: getting ip for local machines (ArkEcosystem#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored and vmunich committed Sep 4, 2019
1 parent b42a5ea commit 9b9c2fb
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/utils.sh
Expand Up @@ -2,5 +2,22 @@

get_ip()
{
sudo ifconfig | fgrep "inet " | egrep -v "inet (127|192)\." | egrep -o "inet (addr:)?([0-9]+\.?){4}" | awk '{print $2}' | head -n 1
IP=$(sudo ifconfig | fgrep "inet " | egrep -v "inet (addr:)?(127|192)\." | egrep -o "inet (addr:)?([0-9]+\.?){4}" | egrep -o "([0-9]+\.?){4}" | head -n 1)

if [ ! -z "$IP" ]; then
echo "$IP"
else
get_local_ip
fi
}

get_local_ip()
{
IP=$(sudo ifconfig | fgrep "inet " | egrep -v "inet (addr:)?(127)\." | egrep -o "inet (addr:)?([0-9]+\.?){4}" | egrep -o "([0-9]+\.?){4}" | head -n 1)

if [ ! -z "$IP" ]; then
echo "$IP"
else
echo "127.0.0.1"
fi
}

0 comments on commit 9b9c2fb

Please sign in to comment.