Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Listing all network interfaces
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 673
Location: Belgium

PostPosted: Thu Sep 25, 2008 5:29 pm    Post subject: Listing all network interfaces Reply with quote

Can I get a list of all network interfaces and their properties, from something as close to the kernel as possible (/proc?) ? I want to manipulate the network interfaces from a script.
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Thu Sep 25, 2008 7:04 pm    Post subject: Reply with quote

things like speed/duplex: ethtool <interfacename>
things regarding ip-settings: ip address
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 673
Location: Belgium

PostPosted: Thu Sep 25, 2008 7:42 pm    Post subject: Reply with quote

For the first, I need interface names, and that's exactly my question. The second does help me to identify interfaces.
Back to top
View user's profile Send private message
Mistwolf
Apprentice
Apprentice


Joined: 07 Mar 2007
Posts: 189
Location: Edmonton, AB

PostPosted: Thu Sep 25, 2008 11:36 pm    Post subject: Reply with quote

You mean like:

Code:
ifconfig -s -a
for all interfaces, or
Code:
ifconfig -s
for all active interfaces?
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 673
Location: Belgium

PostPosted: Fri Sep 26, 2008 1:15 pm    Post subject: Reply with quote

Thanks for your reply. I don't understand I didn't think of that myself :s There's also /proc/net/dev. I would also like to show the person using my script some vendor information, like the one you see in a dmesg, when the relevant driver is loaded. How would I go about that? I can do some stuff with hwinfo, but I don't have that on the Gentoo LiveCD.
Back to top
View user's profile Send private message
Mistwolf
Apprentice
Apprentice


Joined: 07 Mar 2007
Posts: 189
Location: Edmonton, AB

PostPosted: Sat Sep 27, 2008 1:30 pm    Post subject: Reply with quote

If you are interested in getting the manufacturer information of the real networking devices, you can try:

Code:
lspci | grep Ethernet


If you want to know which driver was loaded, I am not sure how to go about it.

Hope this helps.
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 673
Location: Belgium

PostPosted: Sat Sep 27, 2008 4:25 pm    Post subject: Reply with quote

Unfortunately, that doesn't map the human readable identification information to a device. Probably /sys can help me out with my original problem

Code:
$ ls /sys/class/net
eth0/  lo/    pan0/  wlan0/
$ cat /sys/class/net/eth0/device/vendor
0x8086
$ cat /sys/class/net/eth0/device/device
0x1019


and then use that to grep in the lspci output.
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 673
Location: Belgium

PostPosted: Sat Sep 27, 2008 6:59 pm    Post subject: Reply with quote

So, it's probably crappy code and a crappy way to do what I wanted, but here's the code for what it's worth

Code:
#! /bin/bash

INTERFACES=( `ls /sys/class/net/` )
NINTERFACES=${#INTERFACES[*]}
for i in `seq 0 $[$NINTERFACES - 1]`;
do
        if [ -e /sys/class/net/${INTERFACES[$i]}/device/device ];
        then
                DEVICEID=`cat /sys/class/net/${INTERFACES[$i]}/device/device | cut -c3-6`
                VENDORID=`cat /sys/class/net/${INTERFACES[$i]}/device/vendor | cut -c3-6`
                PCIADDRESS=`lspci -n | grep ${VENDORID}:${DEVICEID} | cut -c1-7`
                DESCRIPTION=`lspci | grep $PCIADDRESS | awk -F: '{ print $3 }' | cut -c2-`
                echo ${INTERFACES[$i]} $DESCRIPTION
        fi
done
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum