01: import java.net.*;
02: import java.io.*;
03: 
04: public class LocalPortScanner {
05: 
06:   public static void main(String[] args) {
07:     
08:     for (int port = 1; port <= 65535; port++) {
09:       
10:       try {
11:         // the next line will fail and drop into the catch block if
12:         // there is already a server running on the port
13:         // make sure your firewalls are turned off as otherwise
14:         // you will get an error and it looks as if a port is active
15:         ServerSocket server = new ServerSocket(port);
16:       }
17:       catch (IOException e) {
18:         System.out.println("There is a server on port " + port + ".");
19:       } // end try
20:       
21:     } // end for
22: 
23:   }
24:   
25: }