import java.net.ServerSocket; /** * 检查端口是否正在使用 */ public class CheckPort { public static void main(String[] args) { for (int i = 1; i < 8888; i++) { testPort(i); } System.out.println("Completed"); } private static void testPort(int i) { try { ServerSocket sock = new ServerSocket(i); } catch (java.io.IOException e) { System.out.println("端口 " + i + " 正在使用中..."); } } }