Files
awesome-python/website/data/category_intros/network-virtualization.md
T
2026-09-27 11:21:32 +08:00

2.5 KiB

Configure network devices from several vendors through one API with the Python network automation library NAPALM. Scapy forges, sends, and sniffs packets.

How to choose:

  • Configuring network devices from several vendors, or reading their state: NAPALM
  • Forging, sending, sniffing, and dissecting network packets: Scapy

NAPALM talks to network devices of different operating systems through a unified API, to change their configuration or retrieve data from them. pip install napalm installs all the core drivers. Pick the driver for your device's OS with get_network_driver(), like get_network_driver('eos'). Then connect in a with block, which opens and closes the session for you. To change the configuration, load a candidate that replaces the device's config or merges into it, and check the diff with compare_config(). Then apply it with commit_config(), or throw it away with discard_config(). What each driver supports differs, so test your workflow in a lab first.

Scapy sends, sniffs, dissects, and forges network packets, and you can use it as a shell or as a library. Instead of telling you a port is open or closed, it gives you the full decoded packets, so you probe once and interpret many times. Install it with pip install scapy, and on Windows, install Npcap first. Sending packets needs root privileges, so start the shell with sudo scapy, or on Windows from a command prompt with administrator privileges. Build a packet by stacking layers with /, like IP()/TCP(), and fields you don't set get sensible defaults. In your own scripts, import what you need from scapy.all.