Been a while since I put anything useful on here, but here’s one I found when trying to see if I could extract any switch port details to confirm where my NIC’s are physically cabled to.

A google search found this so kudos to Parthiban for that article which I reproduce here for my personal reference.

As root run:

tcpdump -nn -v -i en0 -s 1500 -c 1 'ether[20:2]==0x2000'

And you should get output similar to…

tcpdump: listening on en0, link-type 1, capture size 1500 bytes
18:02:42.394040 snap 0:0:c:20:0 CDP v2, ttl: 180s, checksum: 692 (unverified)
Device-ID (0x01), length: 37 bytes: 'switch-name.mydomain.com'
Version String (0x05), length: 291 bytes:
Cisco Internetwork Operating System Software
IOS (tm) s72033_rp Software (s72033_rp-IPSERVICESK9_WAN-M), Version 12.2 \
(18)SXF16, RELEASE SOFTWARE (fc2)
Technical Support: <a href="http://www.cisco.com/techsupport">http://www.cisco.com/techsupport</a>
Copyright (c) 1986-2009 by cisco Systems, Inc.
Compiled Tue 03-Mar-09 23:54 by kellythw
Platform (0x06), length: 16 bytes: 'cisco WS-C6509-E'
Address (0x02), length: 13 bytes: IPv4 (1) 145.55.1.135
Port-ID (0x03), length: 19 bytes: 'GigabitEthernet2/38'
Capability (0x04), length: 4 bytes: (0x00000029): Router, L2 Switch, IGMP snooping
Prefixes (0x07), length: 10 bytes:  IPv4 Prefixes (2): 127.0.0.0/8 145.55.1.128/26
VTP Management Domain (0x09), length: 5 bytes: 'ASITE'
Native VLAN ID (0x0a), length: 2 bytes: 50
Duplex (0x0b), length: 1 byte: full
AVVID trust bitmap (0x12), length: 1 byte: 0x00
AVVID untrusted ports CoS (0x13), length: 1 byte: 0x00
975 packets received by filter
0 packets dropped by kernel

In this example, en0 is connected to switch switch-name shown as Device-ID and port 2/38 shown as Port-ID. Handy for double checking what is where.

Private