如何扫描计算机的端口,获取指定数量的空闲端口? 同上,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最简单的办法是建议一个socket 连接,然后给这个连接绑上不同的端口上,来个for, socketServer吧?socket我记得不能bind本地的固定端口. public class Test2{ public static void main(String[] args) { String host = "localhost"; int host_count = 10; int j = 1; for (int i = 8010; i > 7990; i--) { if (!connect(host, i)) { int count = j++; if (count > host_count) { return; } System.out.println("空闲端口" + count + ":[" + i + "]"); } } } public static boolean connect(String host, int port) { try { Socket socket = new Socket(host, port); boolean success = socket.isConnected(); if (success) { socket.close(); } return success; } catch (UnknownHostException e) { return false; } catch (IOException e) { return false; } }} 请教如何使用applet获取浏览器的代理服务器信息? 如何在jTable一行中填加JButton? 学习java中打包遇到的问题 org.w3c.dom.DOMImplementationSourceList 用JAVA来启动进程 我快疯了,非典也不过如此,救救我!! 对象数组的构造函数调用问题 我想学JAVA,有几个问题想请教大家。 关于CPU占用问题-jsoup INSERT INTO 语句包含下列未知的字段名:“binID”。确定键入的名称是正确的, 然后重试。 关于异常! 如何打印jtable,用打印机
public static void main(String[] args) {
String host = "localhost";
int host_count = 10;
int j = 1;
for (int i = 8010; i > 7990; i--) {
if (!connect(host, i)) {
int count = j++;
if (count > host_count) {
return;
}
System.out.println("空闲端口" + count + ":[" + i + "]");
}
}
}
public static boolean connect(String host, int port) {
try {
Socket socket = new Socket(host, port);
boolean success = socket.isConnected();
if (success) {
socket.close();
}
return success;
} catch (UnknownHostException e) {
return false;
} catch (IOException e) {
return false;
}
}
}