Direct byte-level control over network packets. Built for security research, penetration testing, and custom network tools.
import nimpacket
# Create a TCP SYN packet
let ipv4 = IPv4Header(
srcIP: parseIPv4("192.168.1.100"),
dstIP: parseIPv4("10.0.0.1"),
protocol: IPPROTO_TCP
)
let tcp = TCPHeader(
srcPort: 12345,
dstPort: 80,
flags: TCP_SYN
)
# Stack layers and serialize
let packet = (ipv4 / tcp).toBytes()
echo "Packet ready: ", packet.len, " bytes"
Ethernet, ARP, IPv4, TCP, UDP, ICMP. Complete control over every header field.
Intuitive / operator to combine layers. Build complex packets with clean syntax.
Pure Nim implementation. No external libraries required. Easy to audit and deploy.
Compiles to machine code. Optimized checksums. Minimal memory allocations.
Compile-time checks prevent common errors. Structured types over raw byte arrays.
Craft packets from scratch or parse raw bytes. Full serialization support.
5 advanced evasion strategies: TinyFragments, OverlapPoison, OutOfOrder, TimeDelayed, PolymorphicRandom.
| Feature | NimPacket | Scapy |
|---|---|---|
| Performance | Native (Fast) | Interpreted (Slow) |
| Dependencies | Zero | Many (Python ecosystem) |
| Type Safety | Strong (Compile-time) | Weak (Runtime) |
| Binary Size | Small (~KB) | Large (Python + libs) |
| Learning Curve | Low | Low |
| Protocol Coverage | Core protocols | Extensive |
| Packet Capture | Manual (raw sockets) | Built-in |
| Security Auditing | Easy (673 lines) | Complex (large codebase) |
$ nimble install nimpacket
import nimpacket
# Create IPv4 header
let ip = IPv4Header(
srcIP: parseIPv4("192.168.1.1"),
dstIP: parseIPv4("8.8.8.8"),
protocol: IPPROTO_UDP
)
# Create UDP header
let udp = UDPHeader(
srcPort: 5353,
dstPort: 53
)
# Stack and serialize
let packet = (ip / udp).toBytes()
let parsed = parsePacket(rawBytes)
if parsed.ipv4Header.isSome:
echo "Source: ", parsed.ipv4Header.get.srcIP
if parsed.tcpHeader.isSome:
echo "Port: ", parsed.tcpHeader.get.dstPort
Craft custom TCP SYN packets for fast port discovery. Build stealth scanners with precise control over packet fields.
Send ARP requests to map network topology. Identify active hosts and their MAC addresses.
Test network applications by sending malformed or edge-case packets. Validate protocol implementations.
Analyze packet structures, test firewall rules, and develop custom network security tools.
Test detection systems with IP fragmentation techniques. Evaluate security controls with advanced evasion strategies.
Comprehensive guides, API reference, and examples available on GitHub. Includes working demos for common network tools.
Read Full Documentation →