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 16:17:50 +08:00
|
|
|
"time"
|
2023-03-24 16:12:11 +08:00
|
|
|
|
2023-03-24 15:46:54 +08:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2023-03-24 16:17:50 +08:00
|
|
|
func TestBatchLookup(t *testing.T) {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
TestLookup(t)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 15:46:54 +08:00
|
|
|
func TestLookup(t *testing.T) {
|
2023-03-24 16:12:11 +08:00
|
|
|
id, _ := gonanoid.Generate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6)
|
2023-03-24 16:17:50 +08:00
|
|
|
originalText := time.Now().Format("2006-01-02 15:04:05.000")
|
2023-03-24 16:12:11 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|