#!/bin/sh # Echos the current IP address. If you want to see the addresses of all # interfaces, provide an argument to this script (e.g., "ip all"). IFACE="" case `uname -s` in Darwin|FreeBSD) if [ "x$1" = "x" ]; then # $ IFACE=`netstat -rn | grep default | grep -v :: | cut -c 65-` fi ;; OpenBSD) if [ "x$1" = "x" ]; then # $ IFACE=`netstat -rn | grep default | cut -c 71-` fi ;; SunOS) if [ "x$1" = "x" ]; then # $ IFACE=`netstat -rna | grep 0.0.0.0 | cut -c 63- | head -1` fi ;; esac if [ "x$IFACE" != "x" ]; then # $ for iface in $IFACE; do echo `/sbin/ifconfig $iface | grep inet | grep -v inet6 | awk '{print $2}'` # $ done exit fi case `uname -s` in Linux) if [ "x$1" = "x" ]; then # $ IFACE=`netstat -rn | grep ^0.0.0.0 | cut -c 74-` fi echo `/sbin/ifconfig $IFACE | grep inet | grep -v inet6 | awk '{print $2}' | sed -e "s/addr://"` ;; *) echo 'unknown' ;; esac