#!/bin/bash
mac_addresses=($(dmesg | grep "eth" | grep "PCIe" | awk -F' ' '{print $8}'))
count=0
for mac in "${mac_addresses[@]}"; do
((count++))
interface=$(ifconfig | grep -B 4 "$mac" | grep -oE "^[^ ]+" | head -n 1 | awk -F":" '{print $1}' )
echo "第$count个口 MAC地址: $mac 对应的物理端口: $interface"
done
标签:count,grep,addresses,mac,网卡,网口,linux,print
From: https://blog.51cto.com/hequan/7815837