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
}
}
}