Skip to content

Commit 934cc22

Browse files
committed
socks proxy support, version bump
1 parent 1c15d03 commit 934cc22

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## 🆒 Features
77
- ✅ Connect as many bots as you want
8+
- ✅ Use SOCKS4 or SOCKS5 proxies
89
- ✅ Receive colored or noncolored chat
910
- ✅ Set connection delay
1011
- ✅ Set message or command on join
@@ -17,7 +18,7 @@ Use of pre-compiled jar from [releases](https://github.com/crpmax/mc-bots/releas
1718
When running, you can write a chat message to the terminal to send it by all bots.
1819

1920
## 🧪 Example
20-
`java -jar mc-bots-1.0.0.jar -s 192.168.0.189:25565 -d 10 11 -r -p BOT_ -c 30`
21+
`java -jar mc-bots-1.2.0.jar -s 192.168.0.189:25565 -d 10 11 -r -p BOT_ -c 30`
2122

2223
<img src="https://imgur.com/XWcckas.png" title="Connected bots" width="350px"/>
2324
<img src="https://imgur.com/CvJq1Io.gif" title="Sending chat message by bots" width="350px"/>
@@ -32,6 +33,8 @@ When running, you can write a chat message to the terminal to send it by all bot
3233
`-n` Do not use color in terminal - useful when the terminal does not support it
3334
`-m` Minimal run - do not use any listeners, will not receive chat, useful for large amounts of bots
3435
`-x` The most minimal run - No listeners, no control, no chat - useful for large amounts of bots for better performance
36+
`-t` Set proxy type - SOCKS4 or SOCKS5
37+
`-l` Set proxy list file
3538

3639
## ⚠ DISCLAIMER
3740
**This app is made for educational and testing purposes only.

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'me.creepermaxcz.mc-bots'
6-
version '1.1.0'
6+
version '1.2.0'
77

88
sourceCompatibility = 1.8
99
targetCompatibility = 1.8
@@ -14,7 +14,7 @@ repositories {
1414
}
1515

1616
dependencies {
17-
implementation 'com.github.Steveice10:MCProtocolLib:1.18-2'
17+
implementation 'com.github.Steveice10:MCProtocolLib:1.18-3'
1818
implementation 'commons-cli:commons-cli:1.5.0'
1919
implementation 'com.diogonunes:JColor:5.2.0'
2020
implementation 'dnsjava:dnsjava:3.4.3'

src/main/java/me/creepermaxcz/mcbots/Bot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Bot(String nickname, InetSocketAddress address, ProxyInfo proxy) {
2929

3030
Log.info("Creating bot", nickname);
3131
protocol = new MinecraftProtocol(nickname);
32-
client = new TcpClientSession(address.getHostString(), address.getPort(), protocol);
32+
client = new TcpClientSession(address.getHostString(), address.getPort(), protocol, proxy);
3333
}
3434

3535
@Override

src/main/java/me/creepermaxcz/mcbots/Main.java

+85-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
package me.creepermaxcz.mcbots;
22

3+
import com.github.steveice10.packetlib.ProxyInfo;
34
import org.apache.commons.cli.*;
45
import org.xbill.DNS.Lookup;
56
import org.xbill.DNS.Record;
67
import org.xbill.DNS.SRVRecord;
78
import org.xbill.DNS.Type;
89

10+
import java.io.*;
911
import java.net.InetAddress;
1012
import java.net.InetSocketAddress;
13+
import java.net.SocketAddress;
14+
import java.nio.charset.StandardCharsets;
15+
import java.nio.file.Files;
16+
import java.nio.file.InvalidPathException;
17+
import java.nio.file.Paths;
1118
import java.security.SecureRandom;
1219
import java.util.ArrayList;
20+
import java.util.Arrays;
21+
import java.util.List;
1322
import java.util.Scanner;
23+
import java.util.stream.Collectors;
24+
import java.util.stream.Stream;
1425

1526
public class Main {
1627

@@ -26,6 +37,12 @@ public class Main {
2637
private static boolean mostMinimal = false;
2738
public static String joinMessage;
2839

40+
private static boolean useProxies = false;
41+
private static ArrayList<InetSocketAddress> proxies = new ArrayList<>();
42+
private static int proxyIndex = 0;
43+
private static int proxyCount = 0;
44+
private static ProxyInfo.Type proxyType;
45+
2946
public static void main(String[] args) throws Exception {
3047

3148
Options options = new Options();
@@ -47,6 +64,9 @@ public static void main(String[] args) throws Exception {
4764
options.addOption("x", "most-minimal", false, "minimal run without any control, just connect the bots");
4865
options.addOption("j", "join-msg", true, "join message / command");
4966

67+
options.addOption("l", "proxy-list", true, "Path to proxy list file with proxy:port on every line");
68+
options.addOption("t", "proxy-type", true, "Proxy type: SOCKS4 or SOCKS5");
69+
5070
CommandLineParser parser = new DefaultParser();
5171
CommandLine cmd = null;
5272

@@ -58,6 +78,45 @@ public static void main(String[] args) throws Exception {
5878
System.exit(1);
5979
}
6080

81+
if (cmd.hasOption('t') && cmd.hasOption('l')) {
82+
String typeStr = cmd.getOptionValue('t').toUpperCase();
83+
84+
//get proxy type
85+
try {
86+
proxyType = ProxyInfo.Type.valueOf(typeStr);
87+
} catch (IllegalArgumentException e) {
88+
Log.error("Inavlid proxy type, use SOCKS4 or SOCKS5.");
89+
System.exit(1);
90+
}
91+
92+
//read proxy list file
93+
try {
94+
Scanner scanner = new Scanner(new File(cmd.getOptionValue('l')));
95+
while (scanner.hasNextLine()) {
96+
try {
97+
String[] parts = scanner.nextLine().trim().split(":");
98+
if (parts.length == 2) {
99+
int port = Integer.parseInt(parts[1]);
100+
proxies.add(new InetSocketAddress(parts[0], port));
101+
proxyCount++;
102+
}
103+
}
104+
catch (Exception ignored) { }
105+
}
106+
scanner.close();
107+
} catch (FileNotFoundException e) {
108+
Log.error("Invalid proxy list file path.");
109+
System.exit(1);
110+
}
111+
112+
if (proxyCount == 0) {
113+
Log.error("No valid proxies found in file");
114+
System.exit(1);
115+
}
116+
117+
useProxies = true;
118+
}
119+
61120

62121
botCount = Integer.parseInt(cmd.getOptionValue('c', "1"));
63122

@@ -119,10 +178,35 @@ public static void main(String[] args) throws Exception {
119178
new Thread(() -> {
120179
for (int i = 0; i < botCount; i++) {
121180
try {
181+
ProxyInfo proxyInfo = null;
182+
if (useProxies) {
183+
InetSocketAddress proxySocket = proxies.get(proxyIndex);
184+
185+
if (!minimal) {
186+
Log.info(
187+
"Using proxy: (" + proxyIndex + ")",
188+
proxySocket.getHostString() + ":" + proxySocket.getPort()
189+
);
190+
}
191+
192+
proxyInfo = new ProxyInfo(
193+
proxyType,
194+
proxySocket
195+
);
196+
197+
//increment or reset current proxy index
198+
if (proxyIndex < (proxyCount - 1)) {
199+
proxyIndex++;
200+
} else {
201+
proxyIndex = 0;
202+
}
203+
204+
}
205+
122206
Bot bot = new Bot(
123207
nickGen.nextNick(),
124208
inetAddr,
125-
null
209+
proxyInfo
126210
);
127211
bot.start();
128212

0 commit comments

Comments
 (0)