View previous topic :: View next topic |
Author |
Message |
Kobboi l33t
Joined: 29 Jul 2005 Posts: 673 Location: Belgium
|
Posted: Thu Sep 25, 2008 5:29 pm Post subject: Listing all network interfaces |
|
|
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 |
|
|
think4urs11 Bodhisattva
Joined: 25 Jun 2003 Posts: 6659 Location: above the cloud
|
Posted: Thu Sep 25, 2008 7:04 pm Post subject: |
|
|
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 |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 673 Location: Belgium
|
Posted: Thu Sep 25, 2008 7:42 pm Post subject: |
|
|
For the first, I need interface names, and that's exactly my question. The second does help me to identify interfaces. |
|
Back to top |
|
|
Mistwolf Apprentice
Joined: 07 Mar 2007 Posts: 189 Location: Edmonton, AB
|
Posted: Thu Sep 25, 2008 11:36 pm Post subject: |
|
|
You mean like:
for all interfaces, or
for all active interfaces? |
|
Back to top |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 673 Location: Belgium
|
Posted: Fri Sep 26, 2008 1:15 pm Post subject: |
|
|
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 |
|
|
Mistwolf Apprentice
Joined: 07 Mar 2007 Posts: 189 Location: Edmonton, AB
|
Posted: Sat Sep 27, 2008 1:30 pm Post subject: |
|
|
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 |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 673 Location: Belgium
|
Posted: Sat Sep 27, 2008 4:25 pm Post subject: |
|
|
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 |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 673 Location: Belgium
|
Posted: Sat Sep 27, 2008 6:59 pm Post subject: |
|
|
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 |
|
|
|