command to use:
1[Email protected] home]#ifconfig-A |grep 'Link EnCap'-a1|grep-V-|awk-V aa=1-V a1=0 'begin{print "---------------------------------------------------------\n| Device\t| Ipaddr\t\t| Bcast\t\t| mask\t\t|\n---------------------------------------------------------"}{if (NR==AA) {aa=aa+2; a1=$1;} else {if ($2~/[0-9]/) {print A1 ": \ T" substr ($2,6) "\ T" substr ($3,7) "\ T" substr ($4,6)}else{print A1 ":" }}}' 2---------------------------------------------------------3| Device | ipaddr | Bcast | Mask |4---------------------------------------------------------5Eth0:192.168.237.200 192.168.237.255 255.255.255.06Lo127.0.0.1 55.0.0.07 Pan0:8TAP0:192.168.0.1 192.168.0.255 255.255.255.0
Command explanation:
The first step:
Ifconfig-a |grep ' Link encap '-a1|grep-v '-' Preliminary treatment:
1[Email protected] home]#ifconfig-A |grep 'Link EnCap'-a1|grep-V'-'2Eth0 Link encap:ethernet HWaddrxx: 0C: in: 2D: $: $ 3inet Addr:192.168.237.200Bcast:192.168.237.255Mask:255.255.255.04 lo Link encap:local Loopback5inet Addr:127.0.0.1Mask:255.0.0.06Pan0 Link encap:ethernet HWaddr be:ba:2d:2a: the:D 77Broadcast Multicast MTU: theMetric:18Tap0 Link encap:ethernet HWaddr 0E: the: ,: c3:c6: the 9inet Addr:192.168.0.1Bcast:192.168.0.255Mask:255.255.255.0
Step Two:
awk Processing:
1 awk 2-V aa=1#定义赋值变量AA 3-V a1=0#定义赋值变量A1 4 '5Begin{print"---------------------------------------------------------\n| Device\t| Ipaddr\t\t| Bcast\t\t| mask\t\t|\n---------------------------------------------------------"} #打印开头描述6 {7 if(nr==AA) #判断NR行数是否和AA相等, the main intent is to determine if the number of rows is odd. 8{aa=aa+2; a1=$1;} #奇数行AA +2 is assigned to the next odd line, the device name of the odd line is assigned to A1 9 Else Ten { One if($2~/[0-9]/ #判断偶数行的第二个域是否含有数字, the number should be configured with an IP address A{Print A1": \ t"SUBSTR ($2,6)"\ t"SUBSTR ($3,7)"\ t"SUBSTR ($4,6)} #有IP配置, print "Device name (A1 device name assignment for odd rows), IP address, broadcast address, mask" - Else -{Print A1":" #没有配置IP, print only "device name (A1 device name assignment on odd rows)" the } - } - '
Linux all network adapter Statistics View Small command