Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show Ethernet drivers on Linux
$ ~/what_eth_drivers.sh
eth0 [52:54:00:aa:bb:cc]: virtio_net (up)
eth1 [52:54:00:dd:ee:ff]: virtio_net (up)
eth2 [52:54:00:99:88:77]: virtio_net (up)
lo [00:00:00:00:00:00]: (unknown)
#!/bin/bash
for f in /sys/class/net/*; do
dev=$(basename $f)
driver=$(readlink $f/device/driver/module)
if [ $driver ]; then
driver=$(basename $driver)
fi
addr=$(cat $f/address)
operstate=$(cat $f/operstate)
printf "%10s [%s]: %10s (%s)\n" "$dev" "$addr" "$driver" "$operstate"
done
@benediktg
Copy link

benediktg commented Nov 4, 2016

Thanks for this nice script. Side note: here I have fixed the warnings that shellcheck would print. 😉

#!/bin/bash
for f in /sys/class/net/*; do
    dev=$(basename "$f")
    driver=$(readlink "$f/device/driver/module")
    if [ "$driver" ]; then
        driver=$(basename "$driver")
    fi
    addr=$(cat "$f/address")
    operstate=$(cat "$f/operstate")
    printf "%10s [%s]: %10s (%s)\n" "$dev" "$addr" "$driver" "$operstate"
done

(Basically variables should be double-quoted to prevent globbing and word splitting.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment