在java中,怎样判断某个端口是否被使用???在线等待! try{}catch(Exception ex){ 如占用,一定报错} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for (int i = 0; i <255; i++){ try { s = new ServerSocket(i); } catch (IOException ex) { System.out.println("端口﹕" + i + " 已被占用"); } try { s.close; } catch (IOException ex) { System.out.println(""); }} import java.net.*;import java.io.*;public class HighPortScanner { public static void main(String args[]) { String host="localhost"; int begin=0; int end=65336; if(args.length>0) { host=args[0]; } if(args.length>1) { begin=Integer.parseInt(args[1]); end=Integer.parseInt(args[2]); } try{ InetAddress theAddress=InetAddress.getByName(host); for(int i=begin;i<end;i++) { BufferedReader networkIn=null; try { Socket theSocket=new Socket(theAddress,i); System.out.println("there is a serve on port"+i+" of "+host); networkIn=new BufferedReader(new InputStreamReader(theSocket.getInputStream())); System.out.println(networkIn.readLine()); } catch (IOException e) { System.out.println("there is no service on port "+i); } }//END FOR }//END TRY catch(UnknownHostException e) { System.err.println(e); } }//END MAIN} support it回复人: littlecpu(嘿,哥们,你欠我分,快给咯) ( ) 信誉:100 2003-05-15 12:35:00 得分:0 try{}catch(Exception ex){ 如占用,一定报错} 算法的问题,为什么布尔变量声明的位置不一样会产生这样的后果? SCJP考题:数组 遍历 var-arg 关于java中server编译出现的一些问题 rs获取结果集,如果不知道字段名字怎么办? 这个三维数组该怎么写啊 使用jfreechart发生的错误.解决后再100 java 怎样调用dll啊? 谁能简单告诉我一下JBuilder怎么用?看帮助文档太费事了! 如何 jBuilder7中怎样才能让光标在正确的位置 求换行符号 有谁可以提供Jbuilder 7(或8)的下载地址?
try {
s = new ServerSocket(i);
}
catch (IOException ex) {
System.out.println("端口﹕" + i + " 已被占用");
}
try {
s.close;
}
catch (IOException ex) {
System.out.println("");
}
}
import java.io.*;public class HighPortScanner {
public static void main(String args[]) { String host="localhost";
int begin=0;
int end=65336;
if(args.length>0) {
host=args[0];
}
if(args.length>1) {
begin=Integer.parseInt(args[1]);
end=Integer.parseInt(args[2]);
} try{
InetAddress theAddress=InetAddress.getByName(host); for(int i=begin;i<end;i++) { BufferedReader networkIn=null; try {
Socket theSocket=new Socket(theAddress,i);
System.out.println("there is a serve on port"+i+" of "+host);
networkIn=new BufferedReader(new InputStreamReader(theSocket.getInputStream()));
System.out.println(networkIn.readLine());
} catch (IOException e) {
System.out.println("there is no service on port "+i);
} }//END FOR
}//END TRY catch(UnknownHostException e) {
System.err.println(e);
}
}//END MAIN}
回复人: littlecpu(嘿,哥们,你欠我分,快给咯) ( ) 信誉:100 2003-05-15 12:35:00 得分:0
try{
}catch(Exception ex)
{
如占用,一定报错
}