我用这个类检测在192.168.1这个网段 都又哪些服务器运行
import java.net.*;
import java.io.*;
public class Seek extends Thread{
static String ip;
static int port;
//static String mas="hello";
//static boolean con=true;
public static void seek(String ip1,int port1){
ip=ip1;
port=port1;
//mas=mas1;
new Seek().start();
//return con;
}
public void run(){
//Socket s=new Socket();
for(int i=2;i<256;i++){
try{
//s.connect(new InetSocketAddress(InetAddress.getByAddress((ip+"."+i).getBytes()),port));
Socket s=new Socket(ip+"."+i,port);
//s.setSoTimeout(1);

//OutputStream os=s.getOutputStream();
//InputStream is=s.getInputStream();
//byte[] buf=new byte[100];
//int len=is.read(buf);
//System.out.println(new String(buf,0,len));
//os.write(mas.getBytes());
// os.close();
//is.close();
//s.close();
//System.out.print("conn=true qian");
//con=true;
System.out.println(ip+"."+i+"con");
}
catch (Exception ex) {
//ex.printStackTrace();//System.out.print("conn=false qian");
//con=false;//System.out.print("conn=false hou");
System.out.println(ip+"."+i+"nocon");
}
}

}

public static void main (String[] args) {
Seek.seek("192.168.1",6000); }
}
可以完成我想要的功能,但是速度不是很理想。需要非常多的时间才能检测完毕,这样当然不行,请教一个更好的方法,谢谢。