-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsynscan.go
63 lines (51 loc) · 1.07 KB
/
synscan.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
61
62
63
// SPDX-License-Identifier: GPL-3.0-or-later
// SYN Scanning example
package main
import (
"fmt"
"net"
"time"
"github.com/robgonnella/go-lanscan/pkg/network"
"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)
}
mac1, err := net.ParseMAC("00:00:00:00:00:00")
if err != nil {
panic(err)
}
targets := []*scanner.ArpScanResult{
{
IP: net.ParseIP("192.168.1.2"),
MAC: mac1,
},
}
ports := []string{"22", "111", "2000-4000"}
listenPort := uint16(54321)
synScanner := scanner.NewSynScanner(
targets,
userNet,
ports,
listenPort,
scanner.WithIdleTimeout(time.Second*5),
)
go func() {
if err := synScanner.Scan(); err != nil {
panic(err)
}
}()
for result := range synScanner.Results() {
switch result.Type {
case scanner.SYNResult:
fmt.Printf("syn scan result: %+v\n", result.Payload.(*scanner.SynScanResult))
case scanner.SYNDone:
fmt.Println("syn scanning complete")
return
}
}
}