1. 程式人生 > >linux獲取網絡卡資訊

linux獲取網絡卡資訊

sar -n DEV 1 1|grep -E "(Average)|(平均)"|awk '{if(NR>1){a="";"dmesg |grep "$2"|grep \"Link is up\""|getline a;if(match(a,/Link is up at ([0-9]+)/,k)){print $0"\t"($5+$6)*8*100/1000/k[1]}else{print $0"\t-"};ip="-";mac="-";while("ifconfig "$2|getline b){if(match(b,/inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9])/,p)){ip=p[1]}if(match(b,/HWaddr ([0-9a-zA-Z:]*)/,o)){mac=o[1]}}print "\t"ip"\t"mac}else{print $0"\tnetPct\tip\tmac"}}'