PortScanner

public static void scan(InetAddress remote) {

  String hostname = remote.getHostName();
  for (int port = 1; 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 ex) {
      // The remote host is not listening on this port
    }
  }

}

Previous | Next | Top | Cafe con Leche

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