← ARCHIVE
#Go#Networking#Security#Benchmarks

Go Raw Packet Scanner vs Nmap: Benchmarks & Design

AUTHOR:ROUNAK
//DATE: 2026-11-30//READ_TIME: 3 min read

nmap is the standard tool for network discovery and security auditing, and for good reason: its OS fingerprinting, NSE scripting engine, and adaptive timing algorithms are battle-tested across decades. However, when you need an embeddable, high-throughput port and topology scanner inside a Go microservice or automated CI pipeline, shelling out to nmap introduces process-spawning overhead and XML parsing friction.

While engineering Revealr, we built a custom raw-socket SYN and ARP scanner in Go. Below is how the Go implementation compares to nmap in architecture and throughput.

Architecture: Go Goroutines vs Nmap Event Loop

nmap uses a C/C++ single-process event loop (nsock) with adaptive congestion control. Our Go scanner separates packet transmission from packet capture into two dedicated pipelines connected by lock-free ring buffers:

  1. TX Worker Pool: Crafts raw IPv4/TCP SYN frames with gopacket and writes them directly to a raw socket (AF_INET, SOCK_RAW) with rate-limiting tokens.
  2. RX Capture Loop: Reads incoming SYN+ACK and RST frames via AF_PACKET / libpcap with a kernel BPF filter (tcp[tcpflags] & (tcp-syn|tcp-rst) != 0) so user space only processes relevant responses.

Using a kernel-level BPF filter is critical: it prevents Go's runtime from allocating memory for unrelated background traffic on busy interfaces.

Go Raw Scanner vs Nmap Comparison

| Metric / Capability | Custom Go SYN Scanner (Revealr) | Nmap (-sS -T4) | | :--- | :--- | :--- | | Deployment Model | Single static Go binary / library | External C++ CLI binary | | Concurrency Model | Bounded goroutines + channel ring | C++ nsock event loop | | Packet Filtering | Kernel BPF filter before user space | Internal libpcap + nsock | | Output Integration | Native Go structs & JSON topology | Stdout or XML (-oX) parsing | | OS / Service Fingerprinting | Lightweight banner + TTL heuristics | Full Nmap DB + NSE scripts | | Best Use Case | Fast asset discovery & embedded checks | Deep interactive pentesting |

Avoiding Allocation Bottlenecks in Go

At 10,000+ packets per second, naive Go code triggers frequent garbage collection pauses if every packet allocates a new []byte slice or gopacket.Packet struct. We kept GC pressure flat with three rules:

// Pre-allocate reusable serialization buffers per worker
buf := gopacket.NewSerializeBuffer()
opts := gopacket.SerializeOptions{
    ComputeChecksums: true,
    FixLengths:       true,
}

// Reuse buffer across thousands of SYN probes
if err := buf.Clear(); err != nil {
    return err
}
  1. Use sync.Pool for SerializeBuffer: Never allocate a new packet buffer per port probe.
  2. Use gopacket.DecodingLayerParser: Decode Ethernet, IPv4, and TCP headers into pre-allocated structs on the stack instead of full NewPacket heap allocations.
  3. Enforce strict CAP_NET_RAW scoping: Drop root privileges immediately or run the container with only CAP_NET_RAW and CAP_NET_ADMIN.

When to Use Each

Use nmap when you need deep NSE vulnerability scripts, complex firewall evasion, or exhaustive OS fingerprinting. Use a native Go raw-packet scanner when you need sub-second subnet sweeps, programmatic JSON topology graphs, and zero external binary dependencies.

See the full packet-rate measurements and topology graphs on the Revealr Benchmarks page.

SHARE

END OF TRANSMISSION_
[ Return to Archive ]