Skip to content

Commit 1ace253

Browse files
authored
Merge pull request #40 from Swofty-Developments/main
Added tons of documentation and cleaned up some code
2 parents 9a14b43 + b991a9c commit 1ace253

File tree

12 files changed

+311
-290
lines changed

12 files changed

+311
-290
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@v3
24-
- name: Set up JDK 19
24+
- name: Set up JDK 21
2525
uses: actions/setup-java@v3
2626
with:
27-
java-version: '19'
27+
java-version: '21'
2828
distribution: 'temurin'
2929
cache: maven
3030
- name: Build with Maven

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v3
14-
- name: Set up JDK 19
14+
- name: Set up JDK 21
1515
uses: actions/setup-java@v3
1616
with:
17-
java-version: "19"
17+
java-version: "21"
1818
distribution: "temurin"
1919
cache: maven
2020
- name: Build with Maven

pom.xml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<properties>
8-
<maven.compiler.target>19</maven.compiler.target>
9-
<maven.compiler.source>19</maven.compiler.source>
8+
<maven.compiler.target>21</maven.compiler.target>
9+
<maven.compiler.source>21</maven.compiler.source>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1111
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1212
</properties>
1313

1414
<groupId>me.replydev</groupId>
1515
<artifactId>quboscanner</artifactId>
16-
<version>1.0.0</version>
16+
<version>1.0.1</version>
1717

1818
<repositories>
1919
<repository>
@@ -27,7 +27,7 @@
2727
<dependency>
2828
<groupId>org.junit</groupId>
2929
<artifactId>junit-bom</artifactId>
30-
<version>5.9.2</version>
30+
<version>5.10.1</version>
3131
<type>pom</type>
3232
<scope>import</scope>
3333
</dependency>
@@ -38,28 +38,28 @@
3838
<dependency>
3939
<groupId>commons-cli</groupId>
4040
<artifactId>commons-cli</artifactId>
41-
<version>1.5.0</version>
41+
<version>1.6.0</version>
4242
</dependency>
4343
<dependency>
4444
<groupId>org.projectlombok</groupId>
4545
<artifactId>lombok</artifactId>
46-
<version>1.18.24</version>
46+
<version>1.18.30</version>
4747
<scope>provided</scope>
4848
</dependency>
4949
<dependency>
5050
<groupId>com.github.seancfoley</groupId>
5151
<artifactId>ipaddress</artifactId>
52-
<version>5.3.4</version>
52+
<version>5.4.0</version>
5353
</dependency>
5454
<dependency>
5555
<groupId>org.tinylog</groupId>
5656
<artifactId>slf4j-tinylog</artifactId>
57-
<version>2.6.0</version>
57+
<version>2.7.0-M1</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>org.tinylog</groupId>
6161
<artifactId>tinylog-impl</artifactId>
62-
<version>2.6.0</version>
62+
<version>2.7.0-M1</version>
6363
</dependency>
6464
<dependency>
6565
<groupId>com.github.replydev</groupId>
@@ -77,7 +77,7 @@
7777
<plugins>
7878
<plugin>
7979
<artifactId>maven-surefire-plugin</artifactId>
80-
<version>3.0.0-M7</version>
80+
<version>3.2.2</version>
8181
</plugin>
8282
<plugin>
8383
<artifactId>maven-assembly-plugin</artifactId>
@@ -95,13 +95,7 @@
9595
<plugin>
9696
<groupId>org.apache.maven.plugins</groupId>
9797
<artifactId>maven-compiler-plugin</artifactId>
98-
<version>3.10.1</version>
99-
<configuration>
100-
<release>19</release>
101-
<compilerArgs>--enable-preview</compilerArgs>
102-
<source>19</source>
103-
<target>19</target>
104-
</configuration>
98+
<version>3.11.0</version>
10599
</plugin>
106100
</plugins>
107101
</build>

src/main/java/me/replydev/qubo/CLI.java

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,19 @@
55
import lombok.experimental.UtilityClass;
66
import lombok.extern.slf4j.Slf4j;
77

8+
/**
9+
* The CLI class handles the command line interface functionality, including
10+
* initializing the application, printing the logo, and starting the standard
11+
* run process.
12+
* @author ReplyDev
13+
*/
814
@Slf4j
915
@UtilityClass
1016
public class CLI {
1117

12-
private QuboInstance quboInstance;
18+
private static final String VERSION = "1.1.0";
1319

14-
void init(String[] args) {
15-
printLogo();
16-
checkEncodingParameter();
17-
standardRun(args);
18-
19-
log.info(
20-
"Scan terminated - " +
21-
quboInstance.getFoundServers().get() +
22-
" (" +
23-
quboInstance.getUnfilteredFoundServers().get() +
24-
" in total)"
25-
);
26-
System.exit(0);
27-
}
28-
29-
private void checkEncodingParameter() {
30-
if (!isUTF8Mode()) {
31-
log.info("The scanner isn't running in UTF-8 mode!");
32-
log.info(
33-
"Put \"-Dfile.encoding=UTF-8\" in JVM args in order to run the program correctly!"
34-
);
35-
System.exit(-1);
36-
}
37-
}
38-
39-
private void printLogo() {
40-
log.info(
41-
String.format(
42-
"""
20+
private static final String LOGO_TEMPLATE = """
4321
____ _ _____ \s
4422
/ __ \\ | | / ____| \s
4523
| | | |_ _| |__ ___| (___ ___ __ _ _ __ _ __ ___ _ __\s
@@ -49,24 +27,44 @@ private void printLogo() {
4927
5028
By @replydev on Telegram
5129
Version %s
52-
""",
53-
Info.VERSION
54-
)
30+
""";
31+
32+
private QuboInstance quboInstance;
33+
34+
/**
35+
* Initializes the application with given command line arguments.
36+
* @param args The command line arguments.
37+
*/
38+
void init(String[] args) {
39+
printLogo();
40+
standardRun(args);
41+
42+
log.info("Scan terminated - {} ({}) in total",
43+
quboInstance.getFoundServers().get(),
44+
quboInstance.getUnfilteredFoundServers().get()
5545
);
46+
System.exit(0);
47+
}
48+
49+
/**
50+
* Prints the application logo with the current version.
51+
*/
52+
private void printLogo() {
53+
log.info(LOGO_TEMPLATE.replace("%s", VERSION));
5654
}
5755

56+
/**
57+
* Executes the standard application run process.
58+
* @param args The command line arguments.
59+
*/
5860
private void standardRun(String[] args) {
59-
CommandLineArgs commandLineArgs = new CommandLineArgs(args);
60-
quboInstance = new QuboInstance(commandLineArgs);
6161
try {
62+
CommandLineArgs commandLineArgs = new CommandLineArgs(args);
63+
quboInstance = new QuboInstance(commandLineArgs);
6264
quboInstance.run();
6365
} catch (NumberFormatException e) {
64-
commandLineArgs.showHelpAndExit();
66+
log.error("There was an error parsing the numbers.", e);
67+
new CommandLineArgs(args).showHelpAndExit();
6568
}
6669
}
67-
68-
private boolean isUTF8Mode() {
69-
List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
70-
return arguments.contains("-Dfile.encoding=UTF-8");
71-
}
7270
}
Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
package me.replydev.qubo;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import lombok.Value;
46
import lombok.experimental.NonFinal;
57
import me.replydev.utils.IpList;
68
import me.replydev.utils.PortList;
7-
import me.replydev.utils.SearchFilter;
89
import org.apache.commons.cli.*;
910

10-
@Value
11+
/**
12+
* This class is responsible for parsing the command line arguments.
13+
* @author ReplyDev, Swofty
14+
*/
15+
@Getter
1116
public class CommandLineArgs {
1217

13-
Options options;
14-
IpList ipList;
15-
PortList portRange;
16-
boolean skipCommon;
17-
int timeout;
18-
SearchFilter searchFilter;
19-
int count;
20-
21-
@NonFinal
22-
CommandLine cmd;
23-
18+
private final Options options;
19+
private final IpList ipList;
20+
private final PortList portRange;
21+
private final boolean skipCommon;
22+
private final int timeout;
23+
private final SearchFilter searchFilter;
24+
private final int count;
25+
26+
@Setter
27+
private CommandLine cmd;
28+
29+
/**
30+
* Constructor for CommandLineArgs.
31+
* @param command The array of command line arguments to be parsed.
32+
* @throws NumberFormatException If parsing of numeric values fails.
33+
*/
2434
public CommandLineArgs(String[] command) throws NumberFormatException {
2535
options = buildOptions();
2636
CommandLineParser parser = new DefaultParser();
@@ -32,7 +42,7 @@ public CommandLineArgs(String[] command) throws NumberFormatException {
3242
ipList = new IpList(cmd.getOptionValue("i"));
3343
portRange = new PortList(cmd.getOptionValue("p"));
3444
skipCommon = !cmd.hasOption("all");
35-
timeout = Integer.parseInt(cmd.getOptionValue("t"));
45+
timeout = Integer.parseInt(cmd.getOptionValue("t", "1000"));
3646

3747
searchFilter =
3848
SearchFilter
@@ -45,57 +55,33 @@ public CommandLineArgs(String[] command) throws NumberFormatException {
4555
count = Integer.parseInt(cmd.getOptionValue("c", "1"));
4656
}
4757

58+
/**
59+
* Builds the command line options.
60+
* @see Options
61+
* @return Options The command line options.
62+
*/
4863
private static Options buildOptions() {
49-
Option iprange = new Option("i", "iprange", true, "The IP range to scan");
50-
iprange.setRequired(true);
51-
52-
Option portrange = new Option("p", "portrange", true, "The range of ports to scan");
53-
portrange.setRequired(true);
54-
55-
Option timeout = new Option("t", "timeout", true, "TCP connection timeout");
56-
timeout.setRequired(true);
57-
58-
Option count = new Option("c", "pingcount", true, "Number of ping retries");
59-
count.setRequired(false);
60-
61-
Option all = new Option("a", false, "Force Qubo to scan broadcast IPs and common ports");
62-
all.setRequired(false);
63-
64-
Option filterVersion = new Option(
65-
"v",
66-
"filterversion",
67-
true,
68-
"Show only hits with given version"
69-
);
70-
filterVersion.setRequired(false);
71-
72-
Option filterMotd = new Option("m", "filtermotd", true, "Show only hits with given motd");
73-
filterMotd.setRequired(false);
74-
75-
Option filterOn = new Option(
76-
"o",
77-
"minonline",
78-
true,
79-
"Show only hits with at least <arg> players online"
80-
);
81-
filterOn.setRequired(false);
82-
8364
Options options = new Options();
84-
options.addOption(iprange);
85-
options.addOption(portrange);
86-
options.addOption(timeout);
87-
options.addOption(count);
88-
options.addOption(all);
89-
options.addOption(filterVersion);
90-
options.addOption(filterMotd);
91-
options.addOption(filterOn);
65+
66+
options.addRequiredOption("i", "iprange", true, "The IP range to scan");
67+
options.addRequiredOption("p", "portrange", true, "The range of ports to scan");
68+
options.addOption("t", "timeout", true, "TCP connection timeout");
69+
options.addOption("c", "pingcount", true, "Number of ping retries");
70+
options.addOption("a", "all", false, "Force to scan broadcast IPs and common ports");
71+
options.addOption("v", "filterversion", true, "Show only hits with given version");
72+
options.addOption("m", "filtermotd", true, "Show only hits with given motd");
73+
options.addOption("o", "minonline", true, "Show only hits with at least <arg> players online");
9274

9375
return options;
9476
}
9577

78+
/**
79+
* Prints help information using the command line options and exits the program
80+
* with exit code -1.
81+
*/
9682
public void showHelpAndExit() {
9783
HelpFormatter formatter = new HelpFormatter();
98-
formatter.printHelp("-range <arg> -ports <arg> -th <arg> -ti <arg>", options);
84+
formatter.printHelp("Usage: -i <iprange> -p <portrange> -t <timeout> [-c <pingcount>] [...]", options);
9985
System.exit(-1);
10086
}
10187
}

src/main/java/me/replydev/qubo/Info.java

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package me.replydev.qubo;
22

3+
/**
4+
* The Main class is the entry point of Qubo.
5+
* It delegates the start of the application to the CLI class.
6+
* @see CLI
7+
*/
38
public class Main {
49

10+
/**
11+
* The main method that is executed when the program is started.
12+
* It calls the init method of the CLI class, passing along any command line arguments.
13+
* @param args Command line arguments passed to the program.
14+
*/
515
public static void main(String[] args) {
616
CLI.init(args);
717
}
8-
}
18+
}

0 commit comments

Comments
 (0)