title: Java Port scanner
body: <pre><code>import java.net.Socket;
  import java.io.IOException;
  
  public class Main {
  
  
      public static void main(String[] args) {
         String remote = "69.163.44.171";
         int i = 0;
         do {
         try {
         Socket s = new Socket(remote,i);
         System.out.println("Server is listening on port " + i+ " of " + remote);
         s.close();
  
         } catch (IOException ex) {
         System.out.println("Server is not listening on port " + i+ " of " + remote);
      }
         i++;
         } while(i == 55000);
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Server is not listening on port 0 of 69.163.44.171
  BUILD SUCCESSFUL (total time: 0 seconds)
  </code></pre>
  
  <p>i use while loop cause it is faster, now to the question why does it only scan one port? </p>