Skip to content

internal/nmap

import "github.com/nuqs-org/nuqs/internal/nmap"

Package nmap runs Nmap and turns its XML output into model.Host values.

Nmap does the hard low-level work (finding hosts, open ports and what runs on them). We only build the command, run it and read the result.

Functions

Args

Args builds the Nmap arguments for the given targets. Targets must already be validated by the target package.

func Args(targets []string, opt Options) []string

Defined in internal/nmap/nmap.go:32

Parse

Parse reads Nmap XML and returns hosts that are up, with their open ports. Hosts and ports that are down, closed or filtered are left out.

func Parse(r io.Reader) ([]model.Host, error)

Defined in internal/nmap/nmap.go:141

Types

ExecRunner

ExecRunner runs the real nmap binary.

type ExecRunner struct {
    // Path to nmap. Empty means "nmap" from PATH.
    Path string
}

Defined in internal/nmap/nmap.go:57

ExecRunner.Run

Run executes nmap and returns stdout. If nmap fails, the error includes the end of its stderr so the user can see why.

func (r ExecRunner) Run(ctx context.Context, args []string) ([]byte, error)

Defined in internal/nmap/nmap.go:64

Options

Options controls how Nmap is run.

type Options struct {
    // Ports to scan, in Nmap syntax like "22,80,443" or "1-1000".
    // Empty means Nmap's default top 1000 ports.
    Ports string
    // SkipPing scans hosts even if they don't answer ping (Nmap's -Pn).
    SkipPing bool
}

Defined in internal/nmap/nmap.go:22

Runner

Runner runs Nmap with the given arguments and returns its stdout. Tests swap this out so they don't need Nmap installed.

type Runner interface {
    Run(ctx context.Context, args []string) ([]byte, error)
}

Defined in internal/nmap/nmap.go:52

Scanner

Scanner finds hosts and services with Nmap.

type Scanner struct {
    Runner  Runner
    Options Options
}

Defined in internal/nmap/nmap.go:90

Scanner.Scan

Scan runs Nmap against the targets and returns the hosts that are up.

func (s Scanner) Scan(ctx context.Context, targets []string) ([]model.Host, error)

Defined in internal/nmap/nmap.go:96