From e9a7563a9d033fc1957966f58a37ea832a62ed48 Mon Sep 17 00:00:00 2001 From: hiddify-com <114227601+hiddify-com@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:20:51 +0200 Subject: [PATCH] fix: bug --- outbound/xray.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/outbound/xray.go b/outbound/xray.go index 1739c1c65c..73c1ececff 100644 --- a/outbound/xray.go +++ b/outbound/xray.go @@ -87,11 +87,15 @@ type Xray struct { func getRandomFreePort() uint16 { for { - port := rand.Intn(35535) + 30000 // range 30000 to 65535 - l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) + port := rand.Intn(25535) + 30000 // range 30000 to 65535 + l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err == nil { l.Close() - return uint16(port) + l, err := net.Listen("udp", fmt.Sprintf("127.0.0.1:%d", port)) + if err == nil { + l.Close() + return uint16(port) + } } } }