65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"goweb/res"
|
||
|
"goweb/wol"
|
||
|
"net"
|
||
|
|
||
|
"golang.org/x/net/websocket"
|
||
|
)
|
||
|
|
||
|
func Send_start(mac string, ws **websocket.Conn) {
|
||
|
allNetworkInterfaces, err := net.Interfaces()
|
||
|
if err != nil {
|
||
|
println(err)
|
||
|
err = websocket.Message.Send(*ws, res.Get_res_string(200, "", "获取所有网络接口失败", ""))
|
||
|
if err != nil {
|
||
|
// c.Logger().Error(err)
|
||
|
return
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
for i := range allNetworkInterfaces {
|
||
|
if int(allNetworkInterfaces[i].Flags) > 50 {
|
||
|
fmt.Printf("正在往 %s 接口发送\n", allNetworkInterfaces[i].Name)
|
||
|
wol.WakespecifyInterfac(mac, "255.255.255.255", "9", allNetworkInterfaces[i].Name)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
err = websocket.Message.Send(*ws, res.Get_res_string(200, "已经向地址发送 mac: "+mac, "", ""))
|
||
|
if err != nil {
|
||
|
// c.Logger().Error(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
}
|
||
|
func Getall(ws **websocket.Conn) {
|
||
|
type wol struct {
|
||
|
ID int
|
||
|
Name string
|
||
|
Address string
|
||
|
}
|
||
|
var wolarray []wol
|
||
|
wol_item := new(wol)
|
||
|
wol_item.ID = 1
|
||
|
wol_item.Name = "电脑"
|
||
|
wol_item.Address = "10:7B:44:80:F4:6A"
|
||
|
wol_item2 := new(wol)
|
||
|
wol_item2.ID = 2
|
||
|
wol_item2.Name = "aa"
|
||
|
wol_item2.Address = "10:7B:44:80:F4:6A"
|
||
|
wolarray = append(wolarray, *wol_item, *wol_item2)
|
||
|
v, err := json.Marshal(wolarray)
|
||
|
if err != nil {
|
||
|
fmt.Println("marshal failed!", err)
|
||
|
return
|
||
|
}
|
||
|
err = websocket.Message.Send(*ws, res.Get_res_string(200, "", "", string(v)))
|
||
|
if err != nil {
|
||
|
// c.Logger().Error(err)
|
||
|
return
|
||
|
}
|
||
|
}
|