Proof of concept script

This commit is contained in:
adro 2022-02-11 16:06:06 +01:00
parent 573611ac9a
commit 34b2fa0e74
2 changed files with 54 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module miniwol
go 1.17

51
main.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"net"
)
func main() {
macStr := "" // Target Computers MAC Address
// Get a binary representation of that MAC Address
mac, err := net.ParseMAC(macStr)
if err != nil {
panic(err)
}
// Construct the Magic Packet
packet := make([]byte, 102)
index := 0
for i := 0; i < 6; i++ {
packet[index] = 0xFF
index++
}
for i := 0; i < 16; i++ {
for j := 0; j < 6; j++ {
packet[index] = mac[j]
index++
}
}
localAddr, err := net.ResolveUDPAddr("udp4", ":9")
if err != nil {
panic(err)
}
broadcastAddr, err := net.ResolveUDPAddr("udp4", "255.255.255.255:9") // General Broadcast
// broadcastAddr, err := net.ResolveUDPAddr("udp4", "192.168.178.255:9") // Broadcast on most home networks
if err != nil {
panic(err)
}
conn, err := net.DialUDP("udp4", localAddr, broadcastAddr)
if err != nil {
panic(err)
}
defer conn.Close()
conn.Write(packet)
fmt.Println("Successfully sent magic packet")
}