Register
It is currently Fri Apr 18, 2014 5:18 pm

List configured Ethernet Interfaces


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Nov 17, 2010 2:26 pm   
User avatar

Joined: Wed Nov 17, 2010 1:02 pm
Posts: 9
Location: North Bethesda, MD
A quick bash script I put together to display a list of configured ethernet interfaces, and some useful information about them.
Known to work in RHEL4/5/6, Fedora and CentOS.

Code:
#!/bin/bash
echo -e "Interface\tMAC Address\t\tIP Address\tSpeed\t\tLink"

for x in `/sbin/ifconfig | grep Link | awk '{print $1}' | sort | egrep -v 'inet6|lo'`
do

        MAC=$(/sbin/ifconfig $x | grep "Link" | egrep -v inet6\|lo | awk '{print $5}')
        IP=$(/sbin/ifconfig $x | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1)
        SPEED=$(/sbin/ethtool $x 2>/dev/null | grep "Speed" | cut -d: -f2 | sed 's/^[ \t]*//')
        LINK=$(/sbin/ethtool $x 2>/dev/null | grep "Link detected" | cut -d: -f2 | sed 's/^[ \t]*//')

        echo -e $x"\t\t"$MAC"\t"$IP"\t"$SPEED"\t"$LINK

done

echo -e "\n"

exit 0


Last edited by SuperFly on Thu Nov 18, 2010 6:47 am, edited 2 times in total.

Top
 Profile WWW  
 PostPosted: Wed Nov 17, 2010 3:17 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Why would you get the MAC, IP and SPEED variables from $x (the interface name i expect) and then get the LINK status always from eth0 ? A typo perhaps?


Top
 Profile  
 PostPosted: Thu Nov 18, 2010 6:45 am   
User avatar

Joined: Wed Nov 17, 2010 1:02 pm
Posts: 9
Location: North Bethesda, MD
:) Yep, a typo...nice catch! I changed it.


Top
 Profile WWW  
 PostPosted: Mon Mar 28, 2011 7:42 am   

Joined: Mon Mar 28, 2011 7:22 am
Posts: 5
Can you post up the changes you made SuperFly? i assume you added a sudo for ethtool? What about fixing the tabs?

TAB=$'\x09' #Tab Charmap

eh?


Top
 Profile  
 PostPosted: Mon Mar 28, 2011 3:05 pm   

Joined: Mon Mar 28, 2011 7:22 am
Posts: 5
ohh you are using \t , never mind....


Top
 Profile  
 PostPosted: Tue Mar 29, 2011 3:22 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 224
Location: London - UK
I note that ifconfig can no longer be relied on to show all interfaces. The ip command should be used instead, eg "ip addr" :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP