编程知识 cdmana.com

linux 获取网卡状态

#!/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

 

版权声明
本文为[明月惊鹊]所创,转载请带上原文链接,感谢
https://my.oschina.net/mingyuejingque/blog/4838016

Tags linux
Scroll to Top