sk-matrix-project/backend/golang/matrix-dnslog-service/internal/lookup_test.go

45 lines
974 B
Go
Raw Normal View History

2023-03-24 15:46:54 +08:00
package internal
import (
2023-03-24 16:12:11 +08:00
"encoding/hex"
gonanoid "github.com/matoous/go-nanoid"
"matrix-common/pkg/logger"
2023-03-24 15:46:54 +08:00
"fmt"
"math"
"net"
"strings"
"testing"
)
func TestLookup(t *testing.T) {
2023-03-24 16:12:11 +08:00
id, _ := gonanoid.Generate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6)
originalText := strings.Repeat("1234567890", 66)
text := hex.EncodeToString([]byte(originalText))
2023-03-24 15:46:54 +08:00
2023-03-24 16:12:11 +08:00
chunkSize := 18
2023-03-24 15:46:54 +08:00
data := make([]string, 0)
fLen := float64(len(text)) / float64(chunkSize)
l := int(math.Ceil(fLen))
for i := 0; i < l; i++ {
if i == 0 {
data = append(data, text[:chunkSize])
} else {
if (i+1)*chunkSize > len(text) {
data = append(data, text[i*chunkSize:])
} else {
data = append(data, text[i*chunkSize:(i+1)*chunkSize])
}
}
}
logger.Log().Infof("%#v", data)
for i, datum := range data {
2023-03-24 16:12:11 +08:00
_, _ = net.LookupIP(fmt.Sprintf("%s.%s.%d.%s.log.skcks.cn", "a", id, i, datum))
2023-03-24 15:46:54 +08:00
}
2023-03-24 16:12:11 +08:00
_, _ = net.LookupIP(fmt.Sprintf("%s.%s.%s.%s.log.skcks.cn", "e", id, "x", "x"))
2023-03-24 15:46:54 +08:00
}