#!/usr/bin/perl # ifbr - brief network interface list # V0.1.1 Keith Lofstrom KLIC 2008 Dec. 7 use bigint ; # the byte counts can be very large my $ifc ; # interface name my $encap ; # type of encapsulation my $mac ; # mac (hardware) address my $updn ; # interface up or down? my $inet ; # ipv4 internet address my $txrx ; # sum of transmit and receive bytes my $err ; # sum of transmit and receive errors print "interface s encp hdwr address ipv4 address errors rx+tx bytes \n"; print "---------- - ---- ----------------- --------------- ------- ---------------\n"; open (IFOUT, "/sbin/ifconfig |" ); while () { if( /(\w+)\s+Link encap:(\w+)/ ) { $ifc = $1 ; if( $2 eq "Ethernet" ) { $encap = "Enet" } elsif( $2 eq "Local" ) { $encap = "Loop" } elsif( $2 eq "UNSPEC" ) { $encap = "Unsp" } else { $encap = "????" } if( /HWaddr\s+([01234567890ABCDEF:]+)/ ) { $mac=$1; } else { $mac="no hwaddr"; } # in case the following are not found $inet = "none" ; $err = 0 ; $updn = "" ; } elsif( /inet addr:([\d\.]+)/ ) { $inet = $1 ; } elsif( /RUNNING/ ) { if( / UP / ) { $updn="U" } else { $updn=" " } } elsif( /X packets:\d+\s+errors:(\d+)/ ) { $err += $1 ; } elsif( /RX bytes:(\d+).+TX bytes:(\d+)/ ) { $txrx = $1+$2 ; #this is always the last line, hence, the grand output printf "%10s%2s%5s%18s%16s%8s%16s\n" , $ifc,$updn,$encap,$mac,$inet,$err,$txrx ; } } close IFOUT;