java 扫描端口

java 扫描端口

public class VickTest {
 public static void main(String[] args) throws InterruptedException {

  for (int i = 0; i <= 65535; i++) {
   MyTask mt=new MyTask(i);
   Thread thread=new Thread(mt);
   thread.start();
   if(i%100==0){
    Thread.sleep(500);
   }
  }
 }

}

class MyTask implements Runnable{
 int port;
 public MyTask(int port) {
  this.port = port;
 }

 public void run() {
  try {
   Socket s=new Socket("203.208.35.100",port);
   System.out.println("端口"+port+"绑定成功!");
  } catch (UnknownHostException e) {
   System.out.println("主机不明");
  } catch (IOException e) {
   System.out.println("端口"+port+"绑定失败.");
  }
 }
}

你可能感兴趣的:(java 扫描端口)