comparison src/magicpacket.go @ 33:90659c7171ed

add magicpacket.go
author pyon@macmini
date Tue, 13 Aug 2019 19:55:10 +0900
parents
children 523416ca4b83
comparison
equal deleted inserted replaced
32:efa8836fd428 33:90659c7171ed
1 package main
2
3 import (
4 "bytes"
5 "fmt"
6 "net"
7 "log"
8 "os"
9 )
10
11 func main() {
12 if len(os.Args) < 2 {
13 fmt.Fprintln(os.Stderr, "wol mac-address1 mac-address2 ...")
14 os.Exit(1)
15 }
16 for i, m := range os.Args {
17 if i == 0 {
18 continue
19 }
20 hw, err := net.ParseMAC(m)
21 if err != nil {
22 log.Fatal(err)
23 }
24
25 b := [][]byte{bytes.Repeat([]byte{255}, 6), bytes.Repeat([]byte(hw), 16)}
26 pkt := bytes.Join(b, nil)
27
28 conn, err := net.Dial("udp", "255.255.255.255:9")
29 if err != nil {
30 log.Fatal(err)
31 }
32 defer conn.Close()
33
34 conn.Write(pkt)
35 }
36 }
37