Skip to content

Instantly share code, notes, and snippets.

@timhughes
Created March 19, 2021 12:43
Show Gist options
  • Save timhughes/f3cf1ecdfdc72d1757684a1bcb752781 to your computer and use it in GitHub Desktop.
Save timhughes/f3cf1ecdfdc72d1757684a1bcb752781 to your computer and use it in GitHub Desktop.
show_eths.sh
#!/bin/bash
(
for f in $(find /sys/class/net -type l -not -lname '*virtual*' -printf '%p\n'); do
dev=$(basename "$f")
driver=$(readlink "$f/device/driver/module")
if [ "$driver" ]; then
driver=$(basename "$driver")
fi
addr=$(cat "$f/address")
phys_addr=$(cat "$f/phys_port_id" 2>/dev/null|sed 's/.\{2\}/&:/g;s/.$//')
operstate=$(cat "$f/operstate")
mtu=$(cat "$f/mtu")
speed=$(cat "$f/speed")
printf "%s|%s|%s|%s|%s|%s|%s\n" "$dev" "$addr" "$phys_addr" "$driver" "$operstate" "$mtu" "$speed"
done
) | column -s' | ' -o'|' -t|sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment