-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathmain.go
41 lines (34 loc) · 898 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"context"
"fmt"
"log"
"github.com/Ullaakut/nmap/v3"
)
func main() {
scanner, err := nmap.NewScanner(
context.Background(),
nmap.WithTargets("localhost"),
nmap.WithPorts("1-10000"),
nmap.WithServiceInfo(),
nmap.WithVerbosity(3),
)
if err != nil {
log.Fatalf("unable to create nmap scanner: %v", err)
}
progress := make(chan float32, 1)
// Function to listen and print the progress
go func() {
for p := range progress {
fmt.Printf("Progress: %v %%\n", p)
}
}()
result, warnings, err := scanner.Progress(progress).Run()
if len(*warnings) > 0 {
log.Printf("run finished with warnings: %s\n", *warnings) // Warnings are non-critical errors from nmap.
}
if err != nil {
log.Fatalf("unable to run nmap scan: %v", err)
}
fmt.Printf("Nmap done: %d hosts up scanned in %.2f seconds\n", len(result.Hosts), result.Stats.Finished.Elapsed)
}