In this tutorial, learn how to identify the manufacturer of Network Interface Cards ( NIC s) in a Linux environment using powerful bash scripting tools like AWK, GREP, CUT, and TR. Understanding the manufacturer of NICs is crucial for troubleshooting network-related issues and optimizing system performance. Follow along as we delve into the intricacies of bash scripting to streamline the process of NIC identification, empowering you to efficiently manage your Linux-based network infrastructure. Whether you're a seasoned sysadmin or a curious Linux enthusiast, this tutorial will equip you with valuable skills to enhance your networking knowledge. Unlock the potential of your Linux system with this comprehensive guide to NIC manufacturer lookup using bash scripting!
#!/bin/bash
OUI Look file added with ieee-data package
FILE=/usr/share/ieee-data/oui.txt
Check file is there
if [ ! -f $FILE ]; then
echo "$FILE not found, install ieee-data"
exit 1
fi
Display Nic data
Replace : with - to match format of lookup file
ip link show | awk '/ether/{gsub(":","-");print $2}'| while read -r MAC ;
do
OUI_ADDR=$(echo $MAC | cut -d '-' -f 1,2,3 | tr '[:lower:]' '[:upper:]')
ENTRY=$(grep -m 1 -i "$OUI_ADDR" $FILE)
if [ -n "$ENTRY" ]; then
we want to print just the manufacturer which the 3rd field onwards
so we clear the first and second field and make sure we delete leading spaces
before printing complete line
echo $ENTRY | awk '{$1=""; $2=""; gsub("^ ", ""); print $0}'
else
echo "$MAC not found in $FILE"
fi
done
Additionally you can find my video courses on Pluralsight: http://pluralsight.com/training/Authors/Details/andrew-mallett and take time to see my own site http://www.theurbanpenguin.com/
3 Comments