Skip to content

Repository files navigation

CDP Switchport Discovery

Passively discovers which Cisco switch port your machine is connected to by sniffing CDP (Cisco Discovery Protocol) packets. Reports device hostname, IP addresses, connected port, VLANs, IOS version, platform, duplex, PoE, and QoS info.


Quick install

Run this in the directory where you want the tool installed:

curl -sSL https://raw.githubusercontent.com/vherolf/discover-switchport/main/install.sh | bash

Supports Debian/Ubuntu and macOS (Homebrew). Installs all system and Python dependencies, clones the repo, creates a venv, and on Linux sets the required capture capabilities on the Python binary so no sudo is needed at runtime. Running the command again updates everything in place.


Manual install

Debian/Ubuntu:

sudo apt install -y git python3 python3-venv python3-pip libpcap-dev \
    libxcb-keysyms1 libxcb-image0 libxcb-render-util0 libxcb-cursor0 libxcb-icccm4 libcap2-bin
git clone https://github.com/vherolf/discover-switchport.git
cd discover-switchport
python3 -m venv venv
venv/bin/pip install -r requirements.txt
sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' venv/bin/python3

macOS:

brew install git python3
git clone https://github.com/vherolf/discover-switchport.git
cd discover-switchport
python3 -m venv venv
venv/bin/pip install -r requirements.txt

On macOS packet capture requires sudo unless you grant your terminal Full Disk Access or use a dedicated capture tool.


Usage

GUI (recommended)

cd discover-switchport
venv/bin/python3 switchport-scanner-gui.py
  • Interface is auto-detected on start; change it in the dropdown if needed
  • Press Start — CDP packets appear in the table as they arrive
  • New connections are highlighted green and written to CSV automatically
  • Press Browse… to choose a different CSV output path

CLI

cd discover-switchport
venv/bin/python3 switchport-scanner.py
venv/bin/python3 switchport-scanner.py -i eth0
venv/bin/python3 switchport-scanner.py -i eth0 -o /tmp/scan.csv
Flag Default Description
-i / --interface auto-detect Network interface to sniff
-cf / --capturefilter ether dst 01:00:0c:cc:cc:cc BPF capture filter
-o / --output cdp_discovery.csv CSV output path

Build standalone binary (Linux GUI)

sudo bash build.sh

Produces dist/switchport-scanner-gui. Use switchport-scanner.desktop and launch-scanner.sh to integrate it into your desktop environment.


Equivalent tcpdump one-liner

sudo tcpdump -nn -v -i eth0 -s 1500 'ether[20:2] == 0x2000'

About

cisco cdp parser for remote switches in pure python

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages