forked from Ullaakut/nmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (46 loc) · 1.16 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"log"
"github.com/Ullaakut/nmap/v2"
)
func main() {
// Equivalent to
// nmap -sS 192.168.0.10 \
// -D 192.168.0.2,192.168.0.3,192.168.0.4,192.168.0.5,192.168.0.6,ME,192.168.0.8 \
// 192.168.0.72`.
scanner, err := nmap.NewScanner(
nmap.WithTargets("192.168.0.72"),
nmap.WithSpoofIPAddress("192.168.0.10"),
nmap.WithDecoys(
"192.168.0.2",
"192.168.0.3",
"192.168.0.4",
"192.168.0.5",
"192.168.0.6",
"ME",
"192.168.0.8",
),
)
if err != nil {
log.Fatalf("unable to create nmap scanner: %v", err)
}
result, _, err := scanner.Run()
if err != nil {
log.Fatalf("nmap scan failed: %v", err)
}
printResults(result)
}
func printResults(result *nmap.Run) {
// 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)
}