#!/bin/bash SEARCH=${1-.} VLAN_SNIFF_TIME=10 #ETH echo "Port#Address#Speed#State#VLANs#Slaves" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s | %-13s | %-15s\n",$1,$2,$3,$4,$5,$6}' echo "# Ethernet:" for ETH in $(ip addr | awk -F': ' '//dev/null | awk -F': ' '/Link detected/{print $2}' | sed -e 's/yes/Link UP/' -e 's/no/Link DOWN/') SPEED=$(ethtool $ETH 2>/dev/null | awk -F': ' '/Speed/{print $2}' | sed 's/^[0-9]*/& /') MAC=$(ip addr | grep -A1 "[^@]$ETH:" | grep -o '\([0-9abcdef]\{2\}:\)\{5\}[0-9abcdef]\{2\}' | awk '{print $1}' | grep -v 'ff:ff:ff:ff:ff:ff') VLANS=$(timeout ${VLAN_SNIFF_TIME} tcpdump -c 1000 -nni $ETH -e vlan 2>/dev/null | grep -o 'vlan [0-9]*' | sort | uniq | awk '/vlan/{print $2}' | tr '\n' ' ') SLAVES="" for BOND in `ls /proc/net/bonding/* 2>/dev/null`; do if [[ $(grep -c "Slave.*$ETH" $BOND) -gt 0 ]]; then MAC=$(grep -A5 "Slave.*$ETH" $BOND | tail -n1 | grep -oP '(?<=addr: ).*$') fi done if [[ $ETH =~ ^bond ]]; then SLAVES=$(awk '/^Slave Interface/{print $3}' /proc/net/bonding/$ETH | tr '\n' ' ') fi echo "$ETH#$MAC#$SPEED#$STATE#$VLANS#$SLAVES" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s | %-13s | %-15s\n",$1,$2,$3,$4,$5,$6}' done #FC echo "# Fiber Channel:" for PORT in $(ls -d /sys/class/fc_host/host*); do STATE=$(cat $PORT/port_state) SPEED=$(cat $PORT/speed) WWN=$(cat $PORT/port_name | sed 's/^0x//') echo "$PORT#$WWN#$SPEED#$STATE" | awk -F'#' '{printf "%-25s | %-17s | %10s | %-10s\n",$1,$2,$3,$4}' done