This is how it can be done.
Linux:
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
FreeBSD/OpenBSD:
ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'
Solaris:
ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}'