#!/bin/sh # # Eric A. Bautsch - Swangage Computing Ltd. # # shows status of network ports and link partners # # Usage: port_status | all # # # Version Control # v1.0 - Gerald Newns - based on the original idea of Gerald News. # No code remains. # v2.0 - Eric Bautsch - 13 Sep 2004 - re-write from scratch # # DISCLAIMER OF WARRANTIES: THIS TOOLKIT IS OFFERED "AS IS" AND # "WITH ALL FAULTS" AND WITHOUT WARRANTY OF ANY KIND WHATSOEVER. # SWANGAGE DISCLAIMS, AND USERS OF THE TOOLKIT WAIVE, ANY AND ALL EXPRESS # OR IMPLIED WARRANTIES AND REPRESENTATIONS, INCLUDING BUT NOT LIMITED # TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR # PURPOSE, OR NON-INFRINGEMET. THE TOOLKIT IS TO BE USED AT YOUR OWN # RISK. # # NO LIABILITY: IN NO EVENT SHALL SWANGAGE BE LIABLE FOR ANY DIRECT, # INDIRECT, PUNITIVE, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGE # IN CONNECTION WITH OR ARISING OUT OF THE USE OF THE TOOLKIT # (INCLUDING, BUT NOT LIMITED TO, LOSS OF BUSINESS, REVENUE, PROFITS, # USE, DATA, OR OTHER ECONOMIC ADVANTAGE) HOWEVER IT ARISES, WHETHER # FOR BREACH OR IN TORT, EVEN IF SWANGAGE HAS BEEN PREVIOUSLY ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # THIS TOOLKIT IS DISTRIBUTED UNDER THE GNU LICENSE WHICH IS AVAILABLE HERE: # http://www.gnu.org/licenses/gpl.html # usage() { echo "Usage:" echo " $0 {|all}" echo "" echo "you need to be root to run this." echo "" } # parse command line if [ $# -ne 1 -o "`id | awk '{print $1}'`" != "uid=0(root)" ] then usage exit 1 fi int_no=`echo "$1" | perl -pe 's/^.*[a-z]//'` # slightly complicated but # allows for stuff like # e1000g int_type=`echo "$1" | sed "s/${int_no}\\$//"` if [ "${int_type}" = "all" ] then # we do not run the rest of this script now just loop over the i/fs. interfaces=`ifconfig -a | \ grep flags | \ sed 's/:.*//' | \ sort -u | \ egrep -v '^lo'` # echo "checking the following interfaces:\n${interfaces}" # sleep 1 for interface in ${interfaces} do $0 ${interface} done exit 0 fi int_no_length=`echo "$int_no" | wc -c | sed 's/ * *//'` if [ ${int_no_length} -ge 5 ] then # we are using VLAN tagging startcut=`expr ${int_no_length} - 3` endcut=`expr ${int_no_length} - 1` phys_int_no=`echo ${int_no} | \ cut -c${startcut}-${endcut} | \ sed 's/^0*//'` [ "${phys_int_no}" = "" ] && phys_int_no=0 else phys_int_no=${int_no} fi # # setting test device # testing for bge is different - we need /dev/bge # if [ "${int_type}" = "bge" ] then test_device=/dev/${int_type}${phys_int_no} else test_device=/dev/${int_type} fi if [ "${int_type}" != "scman" -a "${int_type}" != "dman" -a "${int_type}" != "bge" ] then ndd -set ${test_device} instance ${phys_int_no} if [ $? -ne 0 ] then echo "failed to set instance to ${test_device}${phys_int_no}." exit 1 fi fi # gather some general info IP=`ifconfig ${int_type}${int_no} | awk '$1 == "inet" {print $2}'` NAME=`awk '$1 == ip {print $2}' ip=$IP /etc/inet/hosts` echo "\nPort ${int_type}${int_no} - ${IP} - ${NAME}" if [ "${int_type}" = "dman" -o "${int_type}" = "scman" ] then ndd -get ${test_device} man_pathgroups_report echo "" exit 0 fi # Get link status link_st=`ndd -get ${test_device} link_status 2> /dev/null` [ "${int_type}" = "ce" ] && \ link_st=`kstat -p ${int_type}:${phys_int_no}:${int_type}${phys_int_no}:link_up | awk '{print $2}'` case "$link_st" in 0 ) link_status="Down" ;; 1 ) link_status="Up" ;; * ) link_status="UNDETERMINED" ;; esac # Get link speed link_sp=`ndd -get ${test_device} link_speed 2> /dev/null` [ "${int_type}" = "ce" ] && \ link_sp=`kstat -p ${int_type}:${phys_int_no}:${int_type}${phys_int_no}:link_speed | awk '{print $2}'` case $link_sp in 0 ) link_speed="10Mb" ;; 1 ) link_speed="100Mb" ;; * ) link_speed="${link_sp}Mb" ;; esac # Get link mode if [ "${int_type}" = "ce" ] then link_md=`kstat -p ${int_type}:${phys_int_no}:${int_type}${phys_int_no}:link_duplex | awk '{print $2}'` case $link_md in 0 ) link_mode="Link Down" ;; 1 ) link_mode="Half Duplex" ;; 2 ) link_mode="Full Duplex" ;; * ) link_mode="${link_md}" ;; esac elif [ "${int_type}" = "bge" ] then link_md=`ndd -get ${test_device} link_duplex 2> /dev/null` case $link_md in 0 ) link_mode="Link Down" ;; 1 ) link_mode="Half Duplex" ;; 2 ) link_mode="Full Duplex" ;; * ) link_mode="${link_md}" ;; esac else link_md=`ndd -get ${test_device} link_mode 2> /dev/null` case $link_md in 0 ) link_mode="Half Duplex" ;; 1 ) link_mode="Full Duplex" ;; * ) link_md=`ndd -get ${test_device} link_duplex 2> /dev/null` case $link_md in 0 ) link_mode="Half Duplex" ;; 1 ) link_mode="Full Duplex" ;; * ) link_mode="${link_md}" ;; esac ;; esac fi echo "Status: ${link_status} ${link_speed} ${link_mode}" # # Get Capabilities # for type in adv lp do if [ "${type}" = "adv" ] then echo "\nPort Capabilities" else echo "\nHub/Switch Capabilities" fi for speed in 1000 100 10 do for duplex in fdx hdx do cap=`ndd ${test_device} ${type}_${speed}${duplex}_cap 2> /dev/null` [ "X${cap}" != "X0" -a "X${cap}" != "X1" ] && \ cap=`kstat -p ${int_type}:${phys_int_no}:${int_type}${phys_int_no}:${type}_cap_${speed}${duplex} 2> /dev/null | awk '{print $2}'` case "${cap}" in 0 ) echo " ${speed}${duplex} -" ;; 1 ) echo " ${speed}${duplex} enabled" ;; esac done done cap=`ndd ${test_device} ${type}_1000autoneg_cap 2> /dev/null` case "${cap}" in 0 ) echo " neg 1000 -" ;; 1 ) echo " auto neg 1000 enabled" ;; esac cap=`ndd ${test_device} ${type}_autoneg_cap 2> /dev/null` [ "X${cap}" != "X0" -a "X${cap}" != "X1" ] && \ cap=`kstat -p ${int_type}:${phys_int_no}:${int_type}${phys_int_no}:${type}_cap_autoneg 2> /dev/null | awk '{print $2}'` case "${cap}" in 0 ) echo " auto neg -" ;; 1 ) echo " auto neg enabled" ;; esac if [ "${type}" = "adv" ] then case "`ndd ${test_device} link_master 2> /dev/null`" in 0 ) echo " int type straight through" ;; 1 ) echo " int type cross over" ;; esac fi done echo ""