Skip to content

Commit

Permalink
avoid ifconfig for ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienMattiussi committed Jul 12, 2024
1 parent f199983 commit d4da871
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bash/getHostIP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if command -v ip 1> /dev/null;
then
if ip -4 addr show docker0 > /dev/null 2>&1 # Docker0 is network for docker under linux and OSX
then
printf $(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
printf $(ip -4 addr show docker0 | grep -oE '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' | head -1)
else
printf $(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') # eth0 is network for docker under wsl
printf $(ip -4 addr show eth0 | grep -oE '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' | head -1) # eth0 is network for docker under wsl
fi
else
printf $(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{ print $2 }' | head -1 | sed -n 's/[^0-9]*\([0-9\.]*\)/\1/p')
Expand Down

0 comments on commit d4da871

Please sign in to comment.