java - get open ports
import java.io.IOException;
import java.net.Socket;
public class App {
public static void main(String[] args) {
Socket tempSocket = new Socket(); // Initialize
boolean isOpened;
// Loop through all the 65536 ports
for (int port = 0; port < 65536; port++) {
// We will assume the current port is opened unless
// An exception occurs
isOpened = true;
try {
// Let's try connecting
tempSocket = new Socket("127.0.0.1", port);
}
catch (IOException e) {
// If an IOException occurs, then port is closed
isOpened = false;
}
finally {
// Close the socket to save resources
tempSocket.close();
}
// If port is opened print a message to the console
if (isOpened) {
String message = String.format("port %d is open", port);
System.out.println(message);
}
}
}
}
Also in Java:
- how to detect if someone clicks on a jpanel in java
- java constructor
- array null pointer java
- how to create a thread local variable in java
- read lines of file randomly java
- how to create a circle in java
- how to create a draw Rectangle in java
- java 8 list stream delete by name
- java initialize string array
- setting up javafx in eclipse
- java nested loop
- spring iterate
- get raondom from array java
- how to add an object to a list of objects in java
- loop and save letters in a string java
- java timestamp
- java swing button on click
- keep jframe on top
- dictionary in java
- java type casting
- create java windows application
- android java convert double to 2 decimal places
- protect java
- make a commet in java