-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
65 lines (53 loc) · 1.58 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
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"log"
"net"
"github.com/enigma522/netcut-cli/networkScan"
)
func main() {
scanFlag := flag.Bool("scan", false, "Scan the network")
CIDR := flag.String("cidr", "", "CIDR for the network scan")
cutFlag := flag.Bool("cut", false, "Cut off a device")
ipAddr := flag.String("ip", "", "IP address of the device to cut off (required if using cut option)")
mac := flag.String("mac", "", "MAC address of the device to cut off (required if using cut option)")
gateway := flag.String("g", "", "Gateway IP address")
ifaceName := flag.String("i", "wlp49s0", "Interface name")
flag.Parse()
scanner := networkscan.NewNetworkScanner(*ifaceName)
defer scanner.Close()
if *scanFlag {
scanner.NetScan(*CIDR)
}
if *cutFlag {
if *ipAddr == "" {
log.Fatal("IP address is required when using the cut option.")
}
var deviceToCut *networkscan.Device
if (*mac == "") {
devices := scanner.NetScan(*ipAddr + "/32")
for _, device := range devices {
if device.IP.String() == *ipAddr {
deviceToCut = &device
break
}
}
}else{
deviceToCut = &networkscan.Device{
IP: net.ParseIP(*ipAddr),
MAC: net.HardwareAddr{},
}
macAddr, err := net.ParseMAC(*mac)
if err != nil {
log.Fatalf("Error parsing MAC address: %v", err)
}
deviceToCut.MAC = macAddr
}
if deviceToCut != nil {
log.Printf("Cut off device: IP: %s, MAC: %s, HOSTNAME: %s\n", deviceToCut.IP, deviceToCut.MAC, deviceToCut.HOSTNAME)
scanner.CutOffDevice(*deviceToCut,*gateway)
} else {
log.Printf("Device with IP: %s not found\n", *ipAddr)
}
}
}