Skip to content

Python Setup

uv is a Python package manager written in Rust. It installs packages 10 to 100 times faster than pip and creates isolated virtual environments automatically. All code examples in this book run inside a single uv-managed environment.

Terminal window
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env

Run this once. It creates a virtual environment and installs every package used in the book:

Terminal window
uv init networking-book-env
cd networking-book-env
uv add scapy netmiko pysnmp dnspython ntplib pymodbus asyncua
Terminal window
source .venv/bin/activate

Scapy needs raw socket access to capture and send frames.

Grant cap_net_raw to the Python interpreter so you do not need to run as root:

Terminal window
sudo setcap cap_net_raw+eip $(which python3)
PackageUsed inPurpose
scapyCh 1, 2, 3, 4, 13Frame capture, crafting, and protocol analysis
netmikoCh 1, 2, 4SSH automation for Hirschmann HiOS switches
pysnmpCh 5SNMP polling and trap reception
dnspythonCh 5DNS queries and diagnostics
ntplibCh 5NTP offset measurement
pymodbusCh 9Modbus TCP client (sync and async)
asyncuaCh 9OPC UA client with security support
import scapy, netmiko, pysnmp, dns, ntplib, pymodbus, asyncua
print("All packages installed.")