This commit is contained in:
xtaci
2022-10-08 17:30:11 +08:00
parent 51e6fed5fc
commit f7a642525c
2 changed files with 25 additions and 8 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"github.com/xtaci/tcpraw"
)
var dialCount int
var dialCount uint64
func dial(config *Config, block kcp.BlockCrypt) (*kcp.UDPSession, error) {
defer func() {
@@ -38,7 +38,7 @@ func dial(config *Config, block kcp.BlockCrypt) (*kcp.UDPSession, error) {
}
// assign remote addr
remoteAddr = fmt.Sprintf("%v:%v", matches[1], minPort+dialCount%(maxPort-minPort+1))
remoteAddr = fmt.Sprintf("%v:%v", matches[1], uint64(minPort)+dialCount%uint64(maxPort-minPort+1))
}
if config.TCP {
+23 -6
View File
@@ -3,19 +3,36 @@ package main
import (
"fmt"
"regexp"
"strconv"
"testing"
)
func TestDial(t *testing.T) {
reg := regexp.MustCompile(`(.*)\:([0-9]{1,5})-?([0-9]{1,5})?`)
strs := reg.FindStringSubmatch("0.0.0.0:20000-21000")
for i := 0; i < len(strs); i++ {
fmt.Println(strs[i])
matches := reg.FindStringSubmatch("www.unknown.unknown:20000-21000")
for i := 0; i < len(matches); i++ {
fmt.Println(matches[i])
}
strs = reg.FindStringSubmatch("0.0.0.0:20000")
for i := 0; i < len(strs); i++ {
fmt.Println(strs[i])
minPort, err := strconv.Atoi(matches[2])
if err != nil {
t.Fatal(err)
}
maxPort, err := strconv.Atoi(matches[3])
if err != nil {
t.Fatal(err)
}
t.Log("minport:", minPort)
t.Log("maxport:", maxPort)
remoteAddr := fmt.Sprintf("%v:%v", matches[1], uint64(minPort)+dialCount%uint64(maxPort-minPort+1))
t.Log("RemoteAddr:", remoteAddr)
testcase2 := "1.2.3.4:20000"
matches = reg.FindStringSubmatch(testcase2)
for i := 0; i < len(matches); i++ {
t.Log(testcase2, "submatch", i, matches[i])
}
}