From 0b19a75d7b714b2c7d9a89fa488cf1dba2ebda2a Mon Sep 17 00:00:00 2001 From: chuzhongzai Date: Sun, 31 Aug 2025 14:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=94=A4=E9=86=92=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=85=81=E8=AE=B8=E6=BC=82=E7=A7=BB=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=94=A4=E9=86=92=E7=AB=AF=E5=8F=A3=E8=A2=AB=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E7=A8=8B=E5=BA=8F=E5=8D=A0=E7=94=A8=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=AE=9E=E7=8E=B0=E5=94=A4=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- src/main/java/lion/CustomUtil.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5ff6309..ba492f6 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store +/.idea/encodings.xml diff --git a/src/main/java/lion/CustomUtil.java b/src/main/java/lion/CustomUtil.java index a10b556..07b71ee 100644 --- a/src/main/java/lion/CustomUtil.java +++ b/src/main/java/lion/CustomUtil.java @@ -5,6 +5,8 @@ import cn.hutool.http.HttpResponse; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Data; +import java.io.IOException; +import java.net.ServerSocket; import java.util.concurrent.atomic.AtomicInteger; @@ -25,4 +27,15 @@ public class CustomUtil { } } } + + public static int _findIdlePort(int port) { + for(int i=port; i<65535; i++){ + try(ServerSocket ignored = new ServerSocket(i)){ + ignored.close(); + return i; + }catch (IOException ignored) { + } + } + return -1; + } }