Skip to content

Instantly share code, notes, and snippets.

@amsterdatech
Forked from henriquemenezes/get_ip.sh
Created February 18, 2020 04:22
Show Gist options
  • Save amsterdatech/9a6dfaa0d8a6062aa08cc8556c20f90b to your computer and use it in GitHub Desktop.
Save amsterdatech/9a6dfaa0d8a6062aa08cc8556c20f90b to your computer and use it in GitHub Desktop.
Get current IP addresses
#!/bin/sh
IP=""
OS=`uname`
case "${OS}" in
Linux)
IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
;;
FreeBSD|OpenBSD)
IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'`
;;
SunOS)
IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '`
;;
Darwin)
IP=`ifconfig | grep inet | grep -v '127.0.0.1' | awk '{ print $2 }'`
;;
*)
IP="Unknown"
;;
esac
echo "$IP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment