/* ............... START ............... */
import java.net.*;
public class JavaPortScan {
public static void main(String[] args) {
for (int port = 1; port <= 65535; port++) {
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress("localhost", port), 1000);
socket.close();
System.out.println("Port " + port + " is open");
} catch (Exception ex) {
}
}
}
}
/* ............... END ............... */
输出
Port 22 is open
Port 53 is open
Port 80 is open
Port 111 is open
Port 631 is open
Port 3306 is open
Port 48360 is open