Skip to content

Commit

Permalink
1.0 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
n0nexist committed Feb 10, 2023
1 parent c5b4647 commit bc002ab
Show file tree
Hide file tree
Showing 20 changed files with 931 additions and 0 deletions.
Binary file added lib/BungeeCord.jar
Binary file not shown.
Binary file added lib/dnsjava-2.1.3.jar
Binary file not shown.
Binary file added lib/log4j-1.2.17.jar
Binary file not shown.
Binary file added lib/lombok-1.18.26.jar
Binary file not shown.
Binary file added lib/slf4j-api-1.7.2.jar
Binary file not shown.
Binary file added lib/slf4j-log4j12-1.7.2.jar
Binary file not shown.
12 changes: 12 additions & 0 deletions masscannot.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>BUNGEECORD</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>www.n0nexist.gq</groupId>
<artifactId>masscannot</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
26 changes: 26 additions & 0 deletions src/main/java/www/n0nexist/gq/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package www.n0nexist.gq;

public class Main {
public static void main(String[] args) {

System.out.println("\n\033[3;33m" +
"8b d8 db .dP\"Y8 .dP\"Y8 dP\"\"b8 db 88b 88 88b 88 dP\"Yb 888888 \n" +
"88b d88 dPYb `Ybo.\" `Ybo.\" dP `\" dPYb 88Yb88 88Yb88 dP Yb 88 \n" +
"88YbdP88 dP__Yb o.`Y8b o.`Y8b Yb dP__Yb 88 Y88 88 Y88 Yb dP 88 \n" +
"88 YY 88 dP\"\"\"\"Yb 8bodP' 8bodP' YboodP dP\"\"\"\"Yb 88 Y8 88 Y8 YbodP 88 \n\033[0m");

System.out.println("a masscan minecraft server checker by www.n0nexist.gq");

try {
String tocheck = args[0];
int thrs = Integer.parseInt(args[1]);
OutputFile.init(args[2]);
OutputFile.write("MASSCANNOT BY WWW.N0NEXIST.GQ");
System.out.println("* parsing xml file..");
XMLParser.parseXML(tocheck,thrs);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("usage => java -jar masscannot.jar [masscan xml file] [threads] [output file]");
}

}
}
26 changes: 26 additions & 0 deletions src/main/java/www/n0nexist/gq/OutputFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package www.n0nexist.gq;

import java.io.FileWriter;
import java.io.IOException;

public class OutputFile {
private static FileWriter fileWriter;
private static String filename;

public static void init(String filename) {
OutputFile.filename = filename;
try {
fileWriter = new FileWriter(filename, true);
} catch (IOException e) {
e.printStackTrace();
}
}

public static void write(String text) {
try {
fileWriter.write(text + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
82 changes: 82 additions & 0 deletions src/main/java/www/n0nexist/gq/XMLParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package www.n0nexist.gq;
import www.n0nexist.gq.utils.PingAndCheck;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class XMLParser {
private static final String ADDR_REGEX = "address addr=\".*?\"";
private static final String PORT_REGEX = "portid=\".*?\"";

public static void parseXML(String fileName, int numThreads) {
List<String> lines = readLinesFromFile(fileName);
int linesPerThread = lines.size() / numThreads;

List<Thread> threads = new ArrayList<>();

for (int i = 0; i < numThreads; i++) {
try {
int startIndex = i * linesPerThread;
int endIndex = (i + 1) * linesPerThread - 1;
if (i == numThreads - 1) {
endIndex = lines.size() - 1;
}
List<String> subList = lines.subList(startIndex, endIndex + 1);
try {
threads.add(new Thread(() -> {
for (String line : subList) {
String address = extractValue(line, ADDR_REGEX);
int port = Integer.parseInt(extractValue(line, PORT_REGEX));
hellomf(address, port);
}
}));
}catch(Exception ee){}
}catch(Exception eee){}
}

for (Thread thread : threads) {
thread.start();
}

for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

private static String extractValue(String line, String regex) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
String matchedString = matcher.group();
return matchedString.split("\"")[1];
}
return null;
}

private static List<String> readLinesFromFile(String fileName) {
List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return lines;
}

private static void hellomf(String address, int port) {
PingAndCheck.processServer(address,port);
}

}
189 changes: 189 additions & 0 deletions src/main/java/www/n0nexist/gq/mcserverping/MCPing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* Copyright 2014 jamietech. All rights reserved.
* https://github.com/jamietech/MinecraftServerPing
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
*/
package www.n0nexist.gq.mcserverping;

import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.xbill.DNS.*;
import org.xbill.DNS.Record;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class MCPing {

private static final Gson GSON = new Gson();
private static final String SRV_QUERY_PREFIX = "_minecraft._tcp.%s";

/**
* Fetches a {@link MCPingResponse} for the supplied hostname.
* <b>Assumed timeout of 2s and port of 25565.</b>
*
* @param address - a valid String hostname
* @return {@link MCPingResponse}
* @throws IOException
*/
public static MCPingResponse getPing(final String address) throws IOException {
return getPing(MCPingOptions.builder().hostname(address).build());
}

/**
* Fetches a {@link MCPingResponse} for the supplied options.
*
* @param options - a filled instance of {@link MCPingOptions}
* @return {@link MCPingResponse}
* @throws IOException
*/
public static MCPingResponse getPing(final MCPingOptions options) throws IOException {

Preconditions.checkNotNull(options.getHostname(), "Hostname cannot be null.");

String hostname = options.getHostname();
int port = options.getPort();

try {

Record[] records = new Lookup(String.format(SRV_QUERY_PREFIX, hostname), Type.SRV).run();

if (records != null) {

for (Record record : records) {
SRVRecord srv = (SRVRecord) record;

hostname = srv.getTarget().toString().replaceFirst("\\.$", "");
port = srv.getPort();
}

}
} catch (TextParseException e) {
e.printStackTrace();
}

String json;
long ping = -1;

try (final Socket socket = new Socket()) {

long start = System.currentTimeMillis();
socket.connect(new InetSocketAddress(hostname, port), options.getTimeout());
ping = System.currentTimeMillis() - start;

try (DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
//> Handshake
ByteArrayOutputStream handshake_bytes = new ByteArrayOutputStream();
DataOutputStream handshake = new DataOutputStream(handshake_bytes)) {

handshake.writeByte(MCPingUtil.PACKET_HANDSHAKE);
MCPingUtil.writeVarInt(handshake, options.getProtocolVersion());
MCPingUtil.writeVarInt(handshake, options.getHostname().length());
handshake.writeBytes(options.getHostname());
handshake.writeShort(options.getPort());
MCPingUtil.writeVarInt(handshake, MCPingUtil.STATUS_HANDSHAKE);

MCPingUtil.writeVarInt(out, handshake_bytes.size());
out.write(handshake_bytes.toByteArray());

//> Status request
out.writeByte(0x01); // Size of packet
out.writeByte(MCPingUtil.PACKET_STATUSREQUEST);

//< Status response
MCPingUtil.readVarInt(in); // Size
int id = MCPingUtil.readVarInt(in);

MCPingUtil.io(id == -1, "Server prematurely ended stream.");
MCPingUtil.io(id != MCPingUtil.PACKET_STATUSREQUEST, "Server returned invalid packet.");

int length = MCPingUtil.readVarInt(in);
MCPingUtil.io(length == -1, "Server prematurely ended stream.");
MCPingUtil.io(length == 0, "Server returned unexpected value.");

byte[] data = new byte[length];
in.readFully(data);
json = new String(data, options.getCharset());

//> Ping
out.writeByte(0x09); // Size of packet
out.writeByte(MCPingUtil.PACKET_PING);
out.writeLong(System.currentTimeMillis());

//< Ping
MCPingUtil.readVarInt(in); // Size
id = MCPingUtil.readVarInt(in);
MCPingUtil.io(id == -1, "Server prematurely ended stream.");
MCPingUtil.io(id != MCPingUtil.PACKET_PING, "Server returned invalid packet.");

}

}

JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
JsonElement descriptionJsonElement = jsonObject.get("description");

if (descriptionJsonElement.isJsonObject()) {

// For those versions that work with TextComponent MOTDs

JsonObject descriptionJsonObject = jsonObject.get("description").getAsJsonObject();

if (descriptionJsonObject.has("extra")) {
descriptionJsonObject.addProperty("text", new TextComponent(ComponentSerializer.parse(descriptionJsonObject.get("extra").getAsJsonArray().toString())).toLegacyText());
jsonObject.add("description", descriptionJsonObject);
}

} else {

// For those versions that work with String MOTDs

String description = descriptionJsonElement.getAsString();
JsonObject descriptionJsonObject = new JsonObject();
descriptionJsonObject.addProperty("text", description);
jsonObject.add("description", descriptionJsonObject);

}

MCPingResponse output = GSON.fromJson(jsonObject, MCPingResponse.class);
output.setPing(ping);
output.setHostname(hostname);
output.setPort(port);

return output;
}

}
Loading

0 comments on commit bc002ab

Please sign in to comment.