-
Notifications
You must be signed in to change notification settings - Fork 1
/
fullscan.go
60 lines (49 loc) · 1.19 KB
/
fullscan.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
56
57
58
59
60
// SPDX-License-Identifier: GPL-3.0-or-later
// Full (ARP + SYN) Scanning example
package main
import (
"fmt"
"github.com/robgonnella/go-lanscan/pkg/network"
"github.com/robgonnella/go-lanscan/pkg/oui"
"github.com/robgonnella/go-lanscan/pkg/scanner"
)
func main() {
// Find default interface info
// i.e. Interface, IPNet, IP
userNet, err := network.NewDefaultNetwork()
if err != nil {
panic(err)
}
vendorRepo, err := oui.GetDefaultVendorRepo()
if err != nil {
panic(err)
}
targets := []string{}
ports := []string{"22", "111", "2000-4000"}
listenPort := uint16(54321)
fullScanner := scanner.NewFullScanner(
userNet,
targets,
ports,
listenPort,
scanner.WithVendorInfo(vendorRepo),
)
go func() {
if err := fullScanner.Scan(); err != nil {
panic(err)
}
}()
for res := range fullScanner.Results() {
switch res.Type {
case scanner.ARPResult:
fmt.Printf("arp scan result: %+v\n", res.Payload.(*scanner.ArpScanResult))
case scanner.ARPDone:
fmt.Println("arp scanning complete")
case scanner.SYNResult:
fmt.Printf("syn scan result: %+v\n", res.Payload.(*scanner.SynScanResult))
case scanner.SYNDone:
fmt.Println("syn scanning complete")
return
}
}
}