#!/bin/sh - # # Usage: ifstat [-v] [] # # Oliver Fromme # # This script displays ethernet interface parameters # on a Sun Solaris machine. If no interface is # specified, all interfaces found on the machine are # listed. # # Use the -v option to see _all_ parameters. Without # it, only the current link parameters are listed. # if [ `/usr/xpg4/bin/id -u` -ne 0 ]; then echo "${0}: You must be root to run me." >&2 exit 1 fi PATH=/sbin:/usr/sbin:/bin:/usr/bin export PATH VERBOSE=0 if [ "x$1" = "x-v" ]; then VERBOSE=1 shift fi NDDSTAT() { echo "${1}${2}:" if [ ! -r /dev/"$1" ]; then echo "/dev/${1}: No such file or directory" >&2 exit 1 fi ndd -set /dev/$1 instance $2 ndd /dev/$1 \? \ | grep -v '^\?' \ | while read KEY JUNK; do VAL=`ndd /dev/$1 "$KEY"` case "$KEY" in link_status) case "$VAL" in 0) COMMENT=" (no carrier)";; 1) COMMENT=" (active)";; *) COMMENT=" (?)" esac ;; link_speed) case "$VAL" in 0) COMMENT=" (10 MBit/s)";; 1) COMMENT=" (100 MBit/s)";; *) COMMENT=" (?)" esac ;; link_mode) case "$VAL" in 0) COMMENT=" (half-duplex)";; 1) COMMENT=" (full-duplex)";; *) COMMENT=" (?)" esac ;; *) COMMENT="" esac if [ -n "$COMMENT" -o $VERBOSE -eq 1 ]; then printf '\t%-20s %s%s\n' "$KEY" "$VAL" "$COMMENT" fi done } if [ $# -lt 1 ]; then ifconfig -a \ | sed -n '/^lo[0-9]*:/!s/^\([a-z][a-z]*\)\([0-9][0-9]*\):.*$/\1 \2/p' \ | while read DEV INS; do NDDSTAT $DEV $INS done else DEV=`expr "x$1" : 'x\([a-z][a-z]*\)'` INS=`expr "x$1" : 'x[a-z][a-z]*\([0-9][0-9*]\)^'` if [ -z "$INS" ]; then INS=0 fi NDDSTAT $DEV $INS fi #--