-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortScanner.java
More file actions
24 lines (22 loc) · 782 Bytes
/
PortScanner.java
File metadata and controls
24 lines (22 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
public class PortScanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter target IP address: ");
String target = scanner.nextLine();
System.out.println("Scanning ports 1-1024 on " + target + "...");
for (int port = 1; port <= 1024; port++) {
try {
Socket socket = new Socket(target, port);
System.out.println("Port " + port + " is OPEN");
socket.close();
} catch (IOException e) {
// port is closed, ignore
}
}
System.out.println("Scan complete.");
scanner.close();
}
}