Example

public static void scan(InetAddress remote) {

  String hostname = remote.getHostName();
  for (int port = 0; port < 65536; port++) {
    try {
      Socket s = new Socket(remote, port); 
      System.out.println("A server is listening on port "
       + port + " of " + hostname);
      s.close();
    }
    catch (IOException e) {
      // The remote host is not listening on this port
    }
  }

}


Previous | Next | Top | Cafe con Leche

Copyright 1999, 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified July 14, 2000