Example Usage
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/Ullaakut/nmap/v4"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
// Equivalent to `/usr/local/bin/nmap -p 80,443,843 google.com facebook.com youtube.com`,
// with a 5-minute timeout.
scanner, err := nmap.NewScanner(
nmap.WithTargets("scanme.nmap.org"),
nmap.WithPorts("80,443,843"),
)
if err != nil {
log.Fatalf("creating nmap scanner: %v", err)
}
result, err := scanner.Run(ctx)
if err != nil {
log.Fatalf("running network scan: %v", err)
}
warnings := result.Warnings()
if len(warnings) > 0 {
log.Printf("warning: %v\n", warnings) // Warnings are non-critical errors from nmap.
}
// Use the results to print an example output
for _, host := range result.Hosts {
if len(host.Ports) == 0 || len(host.Addresses) == 0 {
continue
}
fmt.Printf("Host %q:\n", host.Addresses[0])
for _, port := range host.Ports {
fmt.Printf("\tPort %d/%s %s %s\n", port.ID, port.Protocol, port.State, port.Service.Name)
}
}
fmt.Printf("Nmap done: %d hosts up scanned in %.2f seconds\n", len(result.Hosts), result.Stats.Finished.Elapsed)
}
See also
public-skills-builder
Free
Generate Claude Code bug bounty skills from public HackerOne reports and GitHub writeups — 18 vuln c…
Nmap
Open Source
Kali
The industry-standard network scanner. Discovers hosts, open ports, services, OS versions, and runs …
cazador_unr
Free
[scanner] [TcpListener] [FileMiner] [Subscrabber]…
AD-Attacks-by-Service
Open Source
Active Directory Penetration Testing for Red Teams…
cbrutekrag
Open Source
Penetration tests on SSH servers using brute force or dictionary attacks. Written in C.…
agent-audit
Open Source
Static security scanner for LLM agents — prompt injection, MCP config auditing, taint analysis. 49 r…