Skip to content

Instantly share code, notes, and snippets.

@scottstanfield
Created May 5, 2012 03:54
Show Gist options
  • Save scottstanfield/2599488 to your computer and use it in GitHub Desktop.
Save scottstanfield/2599488 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Shell script scripts to read ip address
OS=`uname`
case $OS in
Linux)
IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
WANIP=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
;;
FreeBSD|OpenBSD|Darwin)
IP=`ifconfig en0 | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'`
WANIP=`curl checkip.dyndns.org 2>/dev/null | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
;;
*)
IP="Unknown"
WANIP="Unknown"
;;
esac
echo "LAN: $IP"
echo "WAN: $WANIP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment