-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathshow-network-port-info
executable file
·36 lines (29 loc) · 1.04 KB
/
show-network-port-info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# This script displays the switch, port, and VLAN for each of the physical
# network interfaces on a Linux server that is connected to Cisco networking
# gear.
#
# Specific interfaces can be passed in on the command line. Other interfaces
# will be ignored.
# Set a timeout on the tcpdump command.
TIMEOUT_SECONDS=60
# Run as root
[ "$EUID" -eq 0 ] || {
echo 'Please run with sudo or as root.'
exit 1
}
# If arguments are supplied, they are a list of NICs.
NICS=$@
[ -z "$NICS" ] && {
# Get a list of physical NICS on the server that are UP. Also, ignore bonded,
# loopback, usb, virtual, tagged (@), and bridged interfaces.
NICS=$(ip link | grep ^[0-9] | grep 'state UP' | cut -d: -f2 | egrep -v 'bond|lo|usb|@|vnet|vir|br' | sort | xargs)
}
# Loop through the NICs.
for NIC in $NICS
do
echo $NIC
timeout $TIMEOUT_SECONDS tcpdump -v -i $NIC -s 1500 -c 1 'ether[20:2] == 0x2000' 2>&1 |egrep 'Device-ID|Port-ID|VLAN' | awk '{print $NF}' | sed "s/'//g"
[ "${PIPESTATUS[0]}" -eq 124 ] && echo 'tcpdump timed out.'
echo
done