Repository navigation
Expand file tree
/
Copy pathportscan.java
More file actions
57 lines (56 loc) · 2.37 KB
/
Copy pathportscan.java
File metadata and controls
57 lines (56 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.net.*;
import java.io.File; // Import the File class
import java.io.IOException; // Import the IOException class to handle errors
import java.io.FileWriter; // Import the FileWriter class
public class portscan {
public static void scan(final int min, final int max) {
final String nomefile = "nkscan-" + min + "-" + max + "range" + ".txt";
try {
final File myObj = new File(nomefile);
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
} else {
System.out.println("File already exists.");
}
} catch (final IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
for (int ip2 = 176; ip2 <= 179; ip2++) {
for (int ip = 1; ip <= 254; ip++) {
System.out.println("Scanning DPRK host 175.45."+ip2+"."+ ip);
//final int[] ports = { 80, 8080 };
for (int port = min; port <= max; port++) {
try {
System.out.println("Scanning on port: " + port);
final Socket socket = new Socket();
final String target = "175.45."+ip2+"."+ ip;
socket.connect(new InetSocketAddress(target, port), 1000);
socket.close();
System.out.println("Service found on " + target);
try {
final FileWriter myWriter = new FileWriter(nomefile, true);
if (port == 25) {
myWriter.write("SMTP found on " + target + ":" + port + "\n");
} else if (port == 21) {
myWriter.write("FTP found on " + target + ":" + port + "\n");
} else if (port == 80 || port == 8080) {
myWriter.write("Webserver found on " + target + ":" + port + "\n");
} else if (port == 5900 || port == 5901) {
myWriter.write("VNC found on " + target + ":" + port + "\n");
} else {
myWriter.write("Service found on " + target + ":" + port + "\n");
}
myWriter.close();
} catch (final IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
// System.out.println("Port " + port + " is open on " + target);
} catch (final Exception ex) {
}
}
}
}
}
}