linux 获取网卡状态

语言: CN / TW / HK
#!/bin/sh

BASEDIR="/sys/class/net"
for i in $( ls $BASEDIR ) 
do 
    if [ -L $BASEDIR/$i ]; then
        carrier=`cat $BASEDIR/$i/carrier 2>/dev/null || echo 0`
        operstate=`cat $BASEDIR/$i/operstate 2>/dev/null || echo 0`
        echo $i:$carrier:$operstate
    fi
done