import java.net.Socket;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
String remote = "69.163.44.171";
int i = 0;
do {
try {
Socket s = new Socket(remote,i);
System.out.println("Server is listening on port " + i+ " of " + remote);
s.close();
} catch (IOException ex) {
System.out.println("Server is not listening on port " + i+ " of " + remote);
}
i++;
} while(i == 55000);
}
Выход:
Server is not listening on port 0 of 69.163.44.171
BUILD SUCCESSFUL (total time: 0 seconds)
Я использую цикл while, потому что он быстрее, теперь вопрос, почему он сканирует только один порт?