-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (50 loc) · 1.29 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
package main
import (
"flag"
"fmt"
"net"
"os"
)
const wolBanner = `
██ ██ ██████ ██
██ ██ ██ ██ ██
██ █ ██ ██ ██ ██
██ ███ ██ ██ ██ ██
███ ███ ██████ ███████
`
func main() {
// Clear the screen
fmt.Print("\033[H\033[2J")
// Display the Wake-on-LAN banner
fmt.Print(wolBanner)
// Parse command-line flags
var targetMAC string
flag.StringVar(&targetMAC, "m", "", "MAC address of the target device (required)")
flag.Parse()
// If targetMAC is not supplied, attempt to read from config
if targetMAC == "" {
macAddress, err := readConfig()
if err != nil {
fmt.Println("Error: MAC address is required and not found in config")
return
}
targetMAC = macAddress
}
// Validate that we now have a MAC address
if targetMAC == "" {
fmt.Println("Error: MAC address is required")
flag.Usage()
os.Exit(1)
}
// Parse MAC address
hwAddr, err := net.ParseMAC(targetMAC)
if err != nil {
fmt.Println("Error parsing MAC address:", err)
return
}
if isDeviceOnline(hwAddr) {
fmt.Println("Device is already online")
return
}
sendMagicPacket(hwAddr)
}