get-host-ip.sh 541 B

123456789101112131415
  1. #!/usr/bin/env bash
  2. set -e
  3. if [[ "$OSTYPE" == "linux-gnu" ]]; then
  4. docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' joystream_default
  5. elif [[ "$OSTYPE" == "darwin"* ]]; then
  6. # try en0 if not set then en1 (Wired or Wireless)
  7. ipconfig getifaddr en0 || ipconfig getifaddr en1
  8. else
  9. echo 'localhost'
  10. fi
  11. # Some alternative approaches (cross platform)
  12. # ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
  13. # ip route | awk '/default/ {print $3}'