1
1
package me .creepermaxcz .mcbots ;
2
2
3
+ import com .github .steveice10 .packetlib .ProxyInfo ;
3
4
import org .apache .commons .cli .*;
4
5
import org .xbill .DNS .Lookup ;
5
6
import org .xbill .DNS .Record ;
6
7
import org .xbill .DNS .SRVRecord ;
7
8
import org .xbill .DNS .Type ;
8
9
10
+ import java .io .*;
9
11
import java .net .InetAddress ;
10
12
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 ;
11
18
import java .security .SecureRandom ;
12
19
import java .util .ArrayList ;
20
+ import java .util .Arrays ;
21
+ import java .util .List ;
13
22
import java .util .Scanner ;
23
+ import java .util .stream .Collectors ;
24
+ import java .util .stream .Stream ;
14
25
15
26
public class Main {
16
27
@@ -26,6 +37,12 @@ public class Main {
26
37
private static boolean mostMinimal = false ;
27
38
public static String joinMessage ;
28
39
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
+
29
46
public static void main (String [] args ) throws Exception {
30
47
31
48
Options options = new Options ();
@@ -47,6 +64,9 @@ public static void main(String[] args) throws Exception {
47
64
options .addOption ("x" , "most-minimal" , false , "minimal run without any control, just connect the bots" );
48
65
options .addOption ("j" , "join-msg" , true , "join message / command" );
49
66
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
+
50
70
CommandLineParser parser = new DefaultParser ();
51
71
CommandLine cmd = null ;
52
72
@@ -58,6 +78,45 @@ public static void main(String[] args) throws Exception {
58
78
System .exit (1 );
59
79
}
60
80
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
+
61
120
62
121
botCount = Integer .parseInt (cmd .getOptionValue ('c' , "1" ));
63
122
@@ -119,10 +178,35 @@ public static void main(String[] args) throws Exception {
119
178
new Thread (() -> {
120
179
for (int i = 0 ; i < botCount ; i ++) {
121
180
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
+
122
206
Bot bot = new Bot (
123
207
nickGen .nextNick (),
124
208
inetAddr ,
125
- null
209
+ proxyInfo
126
210
);
127
211
bot .start ();
128
212
0 commit comments