-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharpscan.go
59 lines (48 loc) · 1.22 KB
/
arpscan.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
// SPDX-License-Identifier: GPL-3.0-or-later
// ARP Scanning example
package main
import (
"fmt"
"time"
"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)
}
// Empty targets will default to scanning interface cidr. If you add something
// to the targets list it will ignore the interface cidr and only scan
// the specified targets.
targets := []string{}
idleTimeout := 5
arpScanner := scanner.NewArpScanner(
targets,
userNet,
scanner.WithIdleTimeout(time.Second*time.Duration(idleTimeout)),
scanner.WithVendorInfo(vendorRepo),
scanner.WithHostnames(true),
)
go func() {
if err := arpScanner.Scan(); err != nil {
panic(err)
}
}()
for result := range arpScanner.Results() {
switch result.Type {
case scanner.ARPResult:
fmt.Printf("arp scan result: %+v\n", result.Payload.(*scanner.ArpScanResult))
case scanner.ARPDone:
fmt.Println("arp scanning complete")
return
}
}
}