通过选项指定strun地址

This commit is contained in:
kony
2025-01-14 18:09:28 +08:00
parent d66d4af63c
commit 25fc3efe3e
3 changed files with 13 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ var (
Arg_conn_type int
Arg_conn_n0 int
Arg_conn_n1 int
Arg_stun_svr_addr string
)
func Help() {
@@ -32,6 +33,8 @@ func Help() {
flag.StringVar(&Arg_redis_pass, "redis_pass", "", "Redis服务密码, 例如: 123456")
flag.IntVar(&Arg_redis_id, "redis_id", 15, "Redis服务可使用的表ID")
flag.StringVar(&Arg_stun_svr_addr, "stun", "", "自定义的STUN服务器地址, 例如: stun.easyvoip.com:3478")
flag.StringVar(&Arg_tun_local_addr, "local", "", "客户端监听的地址端口, 例如: 0.0.0.0:9022")
flag.StringVar(&Arg_tun_remote_addr, "remote", "", "服务端所处网络中, 需要被远程访问的主机地址端口, 例如: 127.0.0.1:22")
flag.StringVar(&Arg_tun_key, "key", "", "自定义, 必须客户端和服务端一致。建议: {name}_{YYYYMMDDHHMM}, 例如: kony_202412140928")

View File

@@ -86,8 +86,6 @@ func GetLocalQuicConn(conn_type int, count int) (quic.Connection, quic.Stream, e
utils.Log().DebugF("发送本端地址: %v", redisJson)
RedisSet(redisJson.RedisTimeOut, &redisJson)
//go m_tun_passive.Start()
default:
if m_tun_active != nil {
m_tun_active.Release()

View File

@@ -198,10 +198,18 @@ func GetWanIpPort2(conn *net.UDPConn) (string, int, int) {
utils.Log().Debug("获取本端地址")
defer conn.SetReadDeadline(time.Time{})
n2 := 0
var stun_svr string
for {
n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(config.GetConfig().StunList))))
stun_svr := config.GetConfig().StunList[n.Int64()]
switch len(config.Arg_stun_svr_addr) {
case 0:
n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(config.GetConfig().StunList))))
stun_svr = config.GetConfig().StunList[n.Int64()]
default:
stun_svr = config.Arg_stun_svr_addr
}
wan_ip, wan_port1, wan_port2, err := getStunIpPort2(conn, stun_svr)
//log.Printf("stun_svr: %s, wan_ip: %s, wan_port1: %d, wan_port2: %d, err: %v", stun_svr, wan_ip, wan_port1, wan_port2, err)
if err != nil {