2025
PyPing & Traceroute — Raw ICMP Network Diagnostics
Python implementations of Unix ping and traceroute using raw ICMP sockets, with configurable packet counts, timing, and detailed RTT statistics.
Overview
Two standalone Python scripts that replicate the classic Unix network diagnostic commands, built from scratch using raw ICMP socket programming — no external libraries required beyond Python’s standard socket and struct modules.
ping
Sends ICMP Echo Request packets to a target host and measures round-trip time for each. Reports:
- Per-packet RTT
- Min / avg / max / standard deviation of round-trip times
- Packet loss percentage
Accepts both IP addresses and hostnames (with automatic DNS resolution). Configurable packet count, interval timing, payload size, and timeout.
traceroute
Maps the network path to a destination by sending ICMP packets with incrementing TTL values. Each router along the path decrements the TTL and returns a Time Exceeded message when it hits zero, revealing the hop. The output shows each intermediate hop and its RTT.
Notes
- Requires root / administrator privileges (raw socket access)
- Output is formatted to match the standard Unix command output
- Pure Python — no external dependencies