mac 校验

This commit is contained in:
Shikong 2022-10-30 02:57:26 +08:00
parent 14054fc776
commit 6184e52b01
2 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,6 @@ func InitService() {
Services = &Service{}
}
func WakeUp(mac string) {
func WakeUp(mac string, port int) {
}

View File

@ -4,10 +4,27 @@ import (
"bytes"
"encoding/hex"
"net"
"regexp"
"strings"
"testing"
)
func TestRegExp(t *testing.T) {
validateMac := func() func(mac string) bool {
exp, _ := regexp.Compile("([0-9a-fA-F]{2}(-|:)?){5}([a-fA-F0-9]{2})")
return func(mac string) bool {
macLen := len(mac)
return exp.MatchString(mac) && (macLen == 12 || macLen == 17)
}
}()
t.Logf("255.255.255.255 %t", validateMac("255.255.255.255"))
t.Logf("FF:FF:FF:FF:FF:FF %t", validateMac("FF:FF:FF:FF:FF:FF"))
t.Logf("00-E0-4C-84-50-EB %t", validateMac("00-E0-4C-84-50-EB"))
t.Logf("00E04C8450EB %t", validateMac("00E04C8450EB"))
t.Logf("00E04C8450EBA %t", validateMac("00E04C8450EBA"))
}
func TestWol(t *testing.T) {
udpAddr, err := net.ResolveUDPAddr("udp", "255.255.255.255:9")
if err != nil {