#!/bin/bash

#zn

#20170825

br=’————————————————————————————-‘;

printf “%-80s\n|%-6s |%-10s |%-10s |%-16s |%-16s |%-16s |\n%-80s\n” $br Device Status Type Ipaddr Bcast Mask $br;

for i in `ifconfig -a |grep ‘Link encap’|awk ‘{print$1}’`; do

DEVICE=$i

STATUS=`ifconfig -a |grep $i -A3|awk ‘/MTU/{print $(NF-3)}’`;

TYPE=` ethtool $i |sed ‘s/]//g’ |awk -F ‘[[]’ ‘/Supported ports/{print$2}’`;

if [ $i == ‘lo’ ];then

STATUS=`ifconfig -a |grep $i -A3|awk ‘/MTU/{print $(NF-2)}’`;

TYPE=’-‘;

IPADDR=`ifconfig -a |grep lo -A1|sed ‘s/ //g’ |awk -F ‘[M:]’ ‘/inetaddr/{print $2}’`;

BCAST=` ifconfig -a |grep lo -A1|sed ‘s/ //g’ |awk -F ‘[M:]’ ‘/inetaddr/{print $4}’`;

MASK=’ ‘;

else

IPADDR=`ifconfig -a |grep $i -A1|sed ‘s/ //g’ |awk -F ‘[BM:]’ ‘/inetaddr/{print $2}’`;

BCAST=` ifconfig -a |grep $i -A1|sed ‘s/ //g’ |awk -F ‘[BM:]’ ‘/inetaddr/{print $4}’`;

MASK=` ifconfig -a |grep $i -A1|sed ‘s/ //g’ |awk -F ‘[BM:]’ ‘/inetaddr/{print $6}’`;

fi

printf “|%-6s |%-10s |%-10s |%-16s |%-16s |%-16s |\n” $DEVICE $STATUS $TYPE $IPADDR $BCAST $MASK

done