Skip to content

Instantly share code, notes, and snippets.

@spelcaster
Created August 12, 2016 14:27
Show Gist options
  • Save spelcaster/2dff77811b737f13bc7fe6bda925b168 to your computer and use it in GitHub Desktop.
Save spelcaster/2dff77811b737f13bc7fe6bda925b168 to your computer and use it in GitHub Desktop.
Get interface name and mac address grouped by vendor and device
#!/bin/bash
OLDIFS=$IFS
IFS=$'\n'
mapfile -t NIC_MODEL < <(lspci | grep -i ethernet | sed 's@[[:alnum:]]\+:[[:alnum:]]\+\.[[:alnum:]]\+\s*@@' | uniq)
IFS=${OLDIFS}
for (( i=0; i < ${#NIC_MODEL[@]}; i++ ))
do
echo ${NIC_MODEL[${i}]}
for addr in $(lspci | grep -i "${NIC_MODEL[${i}]}" | awk '{print $1}')
do
BUS=/sys/bus/pci/devices/$(ls /sys/bus/pci/devices | grep "${addr}")
for device in $(ls ${BUS}/net)
do
echo ${device}
cat ${BUS}/net/${device}/address
done
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment