You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example should be updated to reflect changes in the lib. The WithContext function needs to be used now and the returned warning do not need to be de-ref'd.
ctx, cancel:=context.WithTimeout(context.Background(), 5*time.Minute)
defercancel()
// 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.WithContext(ctx),
nmap.WithTargets("google.com", "facebook.com", "youtube.com"),
nmap.WithPorts("80,443,843"),
)
iferr!=nil {
log.Fatalf("unable to create nmap scanner: %v", err)
}
result, warnings, err:=scanner.Run()
iflen(warnings) >0 {
log.Printf("run finished with warnings: %s\n", warnings) // Warnings are non-critical errors from nmap.
}
iferr!=nil {
log.Fatalf("unable to run nmap scan: %v", err)
}
// Use the results to print an example outputfor_, host:=rangeresult.Hosts {
iflen(host.Ports) ==0||len(host.Addresses) ==0 {
continue
}
fmt.Printf("Host %q:\n", host.Addresses[0])
for_, port:=rangehost.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)
The text was updated successfully, but these errors were encountered:
The example should be updated to reflect changes in the lib. The
WithContext
function needs to be used now and the returnedwarning
do not need to be de-ref'd.The text was updated successfully, but these errors were encountered: