循环呗    java.net.Socket sock;
    String host="localhost";
    int port=70;
    try{
      java.net.InetAddress.getByName(host);
    }catch(UnknownHostException ue){
      ue.printStackTrace();
      return ;
    }
    while(true){
      try{
        sock=new Socket(host,port);
        System.out.println("the port:"+port+" is ok ");
        break;
      }catch(IOException ioe){
        System.out.println("not exists port:"+port);
        port++;
        if (port>=5000)
          break;
      }catch(SecurityException  se){
        se.printStackTrace();
        break;
      }
    }