Skip to content

Commit f1dcf4a

Browse files
author
ReplyDev
committed
Clear commit history
0 parents  commit f1dcf4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3187
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target/
2+
.idea/
3+
outputs/
4+
*.iml
5+
*.iws
6+
.DS_Store
7+
*.txt
8+
*.json
9+
/src/test/

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Quboscanner
2+
3+
## Usage
4+
5+
Java 8+ is required to run the scanner.
6+
7+
To run it in GUI mode just double click it.
8+
9+
To run it in CLI mode use a terminal:
10+
11+
`java -Dfile.encoding=UTF-8 -jar qubo.jar -range 164.132.200.* -ports 25565-25577 -th 500 -ti 1000`
12+
13+
## Building
14+
To build the software clone this repository with Intellij IDEA
15+
and use maven to compile and package the binary.
16+
17+
Feel free to fork and make changes, any pull request is welcome.

pom.xml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<properties>
8+
<maven.compiler.source>1.8</maven.compiler.source>
9+
<maven.compiler.target>1.8</maven.compiler.target>
10+
</properties>
11+
12+
<groupId>me.reply.qubo</groupId>
13+
<artifactId>quboscanner</artifactId>
14+
<version>0.3.6</version>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.google.code.gson</groupId>
19+
<artifactId>gson</artifactId>
20+
<version>2.8.6</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>net.java.dev.jna</groupId>
24+
<artifactId>jna-platform</artifactId>
25+
<version>5.5.0</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.formdev</groupId>
29+
<artifactId>flatlaf</artifactId>
30+
<version>0.27</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.intellij</groupId>
34+
<artifactId>forms_rt</artifactId>
35+
<version>7.0.3</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>commons-cli</groupId>
39+
<artifactId>commons-cli</artifactId>
40+
<version>1.4</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.github.seancfoley</groupId>
44+
<artifactId>ipaddress</artifactId>
45+
<version>5.2.1</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.httpcomponents</groupId>
49+
<artifactId>httpclient</artifactId>
50+
<version>4.5.11</version>
51+
</dependency>
52+
</dependencies>
53+
<build>
54+
<plugins>
55+
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-assembly-plugin</artifactId>
59+
<version>2.4.1</version>
60+
<configuration>
61+
<!-- get all project dependencies -->
62+
<descriptorRefs>
63+
<descriptorRef>jar-with-dependencies</descriptorRef>
64+
</descriptorRefs>
65+
<!-- MainClass in mainfest make a executable jar -->
66+
<archive>
67+
<manifest>
68+
<mainClass>qubo.Main</mainClass>
69+
</manifest>
70+
</archive>
71+
72+
</configuration>
73+
<executions>
74+
<execution>
75+
<id>make-assembly</id>
76+
<!-- bind to the packaging phase -->
77+
<phase>package</phase>
78+
<goals>
79+
<goal>single</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-jar-plugin</artifactId>
87+
<configuration>
88+
<archive>
89+
<manifest>
90+
<mainClass>qubo.Main</mainClass>
91+
</manifest>
92+
</archive>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>

src/main/java/mcping/MCPing.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package mcping;
2+
3+
import java.io.IOException;
4+
import java.net.InetSocketAddress;
5+
import com.google.gson.Gson;
6+
import mcping.data.*;
7+
8+
public class MCPing
9+
{
10+
public FinalResponse getPing(PingOptions options) throws IOException
11+
{
12+
final Gson gson = new Gson();
13+
Pinger a = new Pinger();
14+
a.setAddress(new InetSocketAddress(options.getHostname(),options.getPort()));
15+
a.setTimeout(options.getTimeout());
16+
String json = a.fetchData();
17+
if(json != null){
18+
if(json.contains("{"))
19+
{
20+
if(json.contains("\"modid\"") && json.contains("\"translate\"")){ //it's a forge response translate
21+
return gson.fromJson(json, ForgeResponseTranslate.class).toFinalResponse();
22+
}
23+
else if(json.contains("\"modid\"") && json.contains("\"text\"")){ //it's a normal forge response
24+
return gson.fromJson(json, ForgeResponse.class).toFinalResponse();
25+
}
26+
else if(json.contains("\"modid\"")){ //it's an old forge response
27+
return gson.fromJson(json, ForgeResponseOld.class).toFinalResponse();
28+
}
29+
else if(json.contains("\"extra\"")){ //it's an extra response
30+
return gson.fromJson(json,ExtraResponse.class).toFinalResponse();
31+
}
32+
else if(json.contains("\"text\"")){ //it's a new response
33+
return gson.fromJson(json,NewResponse.class).toFinalResponse();
34+
}
35+
else { //it's an old response
36+
return gson.fromJson(json,OldResponse.class).toFinalResponse();
37+
}
38+
}
39+
}
40+
return null;
41+
}
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package mcping;
2+
3+
public class PingOptions {
4+
5+
private String hostname;
6+
private int port;
7+
private int timeout;
8+
//private String charset = "UTF-8";
9+
10+
public PingOptions setHostname(String hostname) {
11+
this.hostname = hostname;
12+
return this;
13+
}
14+
15+
public PingOptions setPort(int port) {
16+
this.port = port;
17+
return this;
18+
}
19+
20+
public PingOptions setTimeout(int timeout) {
21+
this.timeout = timeout;
22+
return this;
23+
}
24+
25+
/*public PingOptions setCharset(String charset) {
26+
this.charset = charset;
27+
return this;
28+
}*/
29+
30+
String getHostname() {
31+
return this.hostname;
32+
}
33+
34+
int getPort() {
35+
return this.port;
36+
}
37+
38+
public int getTimeout() {
39+
return this.timeout;
40+
}
41+
42+
/*public String getCharset() {
43+
return this.charset;
44+
}*/
45+
46+
}

src/main/java/mcping/Pinger.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package mcping;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.Closeable;
5+
import java.io.DataInputStream;
6+
import java.io.DataOutputStream;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.io.OutputStream;
10+
import java.net.InetSocketAddress;
11+
import java.net.Socket;
12+
13+
class Pinger
14+
{
15+
private InetSocketAddress host;
16+
private int timeout;
17+
18+
void setAddress(InetSocketAddress host)
19+
{
20+
this.host = host;
21+
}
22+
void setTimeout(int timeout)
23+
{
24+
this.timeout = timeout;
25+
}
26+
27+
private int readVarInt(DataInputStream in) throws IOException {
28+
int i = 0;
29+
int j = 0;
30+
int k;
31+
do
32+
{
33+
k = in.readByte();
34+
i |= (k & 0x7F) << j++ * 7;
35+
if (j > 5) {
36+
//throw new RuntimeException("VarInt too big");
37+
return -1;
38+
}
39+
} while ((k & 0x80) == 128);
40+
return i;
41+
}
42+
43+
private void writeVarInt(DataOutputStream out, int paramInt) throws IOException {
44+
for (;;)
45+
{
46+
if ((paramInt & 0xFFFFFF80) == 0)
47+
{
48+
out.writeByte(paramInt);
49+
return;
50+
}
51+
out.writeByte(paramInt & 0x7F | 0x80);
52+
paramInt >>>= 7;
53+
}
54+
}
55+
56+
public String fetchData() throws IOException
57+
{
58+
Socket socket = new Socket();
59+
socket.setSoTimeout(this.timeout);
60+
socket.connect(this.host, this.timeout);
61+
62+
OutputStream outputStream = socket.getOutputStream();
63+
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
64+
InputStream inputStream = socket.getInputStream();
65+
ByteArrayOutputStream b = new ByteArrayOutputStream();
66+
DataOutputStream handshake = new DataOutputStream(b);
67+
68+
handshake.writeByte(0);
69+
writeVarInt(handshake, 4);
70+
writeVarInt(handshake, this.host.getHostString().length());
71+
handshake.writeBytes(this.host.getHostString());
72+
handshake.writeShort(this.host.getPort());
73+
writeVarInt(handshake, 1);
74+
75+
writeVarInt(dataOutputStream, b.size());
76+
dataOutputStream.write(b.toByteArray());
77+
dataOutputStream.writeByte(1);
78+
dataOutputStream.writeByte(0);
79+
DataInputStream dataInputStream = new DataInputStream(inputStream);
80+
81+
int size = readVarInt(dataInputStream);
82+
int id = readVarInt(dataInputStream);
83+
int length = readVarInt(dataInputStream);
84+
85+
if (size < 0 || id < 0 || length <= 0)
86+
{
87+
closeAll(b, dataInputStream, handshake, dataOutputStream, outputStream, inputStream, socket);
88+
return null;
89+
}
90+
91+
byte[] in = new byte[length];
92+
dataInputStream.readFully(in);
93+
closeAll(b, dataInputStream, handshake, dataOutputStream, outputStream, inputStream, socket);
94+
return new String(in); //JSON
95+
}
96+
97+
public void closeAll(Closeable... closeables) throws IOException
98+
{
99+
for (Closeable closeable : closeables)
100+
{
101+
closeable.close();
102+
}
103+
}
104+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mcping.data;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import mcping.rawData.ExtraDescription;
5+
6+
public class ExtraResponse extends MCResponse {
7+
8+
@SerializedName("description")
9+
private ExtraDescription description;
10+
11+
public FinalResponse toFinalResponse(){
12+
return new FinalResponse(players,version,favicon,description.getText());
13+
}
14+
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mcping.data;
2+
3+
import mcping.rawData.Players;
4+
import mcping.rawData.Version;
5+
6+
public class FinalResponse extends MCResponse {
7+
8+
private final String description;
9+
10+
11+
public FinalResponse(Players players, Version version,String favicon,String description){
12+
this.description = description;
13+
this.favicon = favicon;
14+
this.players = players;
15+
this.version = version;
16+
}
17+
18+
public Players getPlayers() {
19+
return players;
20+
}
21+
22+
public Version getVersion() {
23+
return version;
24+
}
25+
26+
public String getDescription() {
27+
return description;
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package mcping.data;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import mcping.rawData.*;
5+
6+
public class ForgeResponse {
7+
8+
@SerializedName("description")
9+
private Description description;
10+
11+
@SerializedName("players")
12+
private Players players;
13+
14+
@SerializedName("version")
15+
private Version version;
16+
17+
@SerializedName("modinfo")
18+
private ForgeModInfo modinfo;
19+
20+
public FinalResponse toFinalResponse(){
21+
version.setName(version.getName() + " FML with " + modinfo.getNMods() + " mods");
22+
return new FinalResponse(players,version,"",description.getText());
23+
}
24+
}

0 commit comments

Comments
 (0)