Skip to content

Commit 3f5a2e3

Browse files
committed
v1.19
1 parent 483d654 commit 3f5a2e3

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ All notable changes to this project will be documented in `CHANGELOG.md`.
55
Nothing has been added.
66

77
## Modified
8-
* Stopping & resuming handling.
8+
* `ServerList` refreshes every 10 seconds.
9+
* Fixed bug where when an offset got to ~252-255, it would stay there and miss out on ***a lot*** of IPs.
910

1011
## Removed
11-
Nothing has been removed.
12+
* The thing that tells you how many IPs are left to scan. It was inaccurate and I'm pretty sure getting & drawing that number to the screen made it lag a lot.
1213

1314
## TODOs
14-
- [ ] Optimise IP generation and inital scanning code.[¹][1]
15+
- [ ] Optimise IP generation and initial scanning code.[¹][1]
1516
- [ ] Optimise code in general.
16-
- [ ] Seperate tool for viewing servers in DB. (code is already here (`ServerList` class), just need to make it seperate)
17-
- [x] ~~Make it save what IP it got to when qutting so that it can resume from that IP on next startup.~~
17+
- [ ] Separate tool for viewing servers in DB. (code is already here (`ServerList` class), just need to make it separate)
18+
- [x] ~~Make it save what IP it got to when quitting so that it can resume from that IP on next startup.~~
1819
- [x] ~~Add a GUI for viewing servers in a nice friendly grid.~~
1920

2021
[1]: https://github.com/StupidRepo/MCScanner/blob/main/src/com/stupidrepo/mcscanner/MCScanner.java#L126

src/com/stupidrepo/mcscanner/MCScanner.java

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.stupidrepo.mcscanner;
22

3-
import java.awt.BorderLayout;
3+
import java.awt.*;
4+
import java.awt.datatransfer.Clipboard;
5+
import java.awt.datatransfer.StringSelection;
6+
import java.awt.event.ActionListener;
47
import java.awt.event.WindowEvent;
58
import java.io.*;
69
import java.net.InetSocketAddress;
@@ -34,7 +37,7 @@ public static void main(String[] var0) {
3437

3538
Logger logger = Logger.getLogger("com.stupidrepo.mcscanner");
3639

37-
float version = 1.17f;
40+
float version = 1.19f;
3841

3942
AtomicReference<String> uri = new AtomicReference<>("mongodb://localhost:27017");
4043

@@ -61,10 +64,9 @@ public static void main(String[] var0) {
6164
frame.setSize(300, 100);
6265
frame.setLayout(new BorderLayout());
6366

64-
double progressThing = (maxRange - minimumRange + 1) * 256 * 256;
6567
ArrayList < Thread > threadList = new ArrayList < Thread > ();
6668

67-
JLabel scannedLabel = new JLabel("Scanned: 0/" + progressThing * 256);
69+
JLabel scannedLabel = new JLabel("Scanned: 0");
6870
scannedLabel.setHorizontalAlignment(0);
6971

7072
frame.add(scannedLabel, "Center");
@@ -86,7 +88,7 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
8688
logger.log(Level.INFO, "Making an '.mcscanner'...");
8789
try {
8890
BufferedWriter writer = new BufferedWriter(new FileWriter(".mcscanner"));
89-
writer.write(String.valueOf(offsetI + "\n" + offsetJ + "\n" + offsetK + "\n" + offsetL));
91+
writer.write(offsetI + "\n" + offsetJ + "\n" + offsetK + "\n" + offsetL);
9092
writer.close();
9193
} catch (IOException e) {
9294
logger.log(Level.SEVERE, "Failed to write '.mcscanner'!");
@@ -132,25 +134,25 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
132134
int thisOffsetJ = offsetJ;
133135
int thisOffsetK = offsetK;
134136
int thisOffsetL = offsetL;
135-
for (int i = thisOffsetI; i <= maxRange; ++i) {
137+
for (int i = 0; i <= (maxRange-thisOffsetI); ++i) {
136138
if(stopping) {
137139
break;
138140
} else {
139141
offsetI = i;
140142
}
141-
for (int j = thisOffsetJ; j <= 255; ++j) {
143+
for (int j = minimumRange; j <= (255-thisOffsetJ); ++j) {
142144
if(stopping) {
143145
break;
144146
} else {
145147
offsetJ = j;
146148
}
147-
for (int k = thisOffsetK; k <= 255; ++k) {
149+
for (int k = 0; k <= (255-thisOffsetK); ++k) {
148150
if(stopping) {
149151
break;
150152
} else {
151153
offsetK = k;
152154
}
153-
for (int l = thisOffsetL; l <= 255; ++l) {
155+
for (int l = 0; l <= (255-thisOffsetL); ++l) {
154156
if(stopping) {
155157
break;
156158
} else {
@@ -168,7 +170,7 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
168170
try {
169171
nextThread.join();
170172
++scanned;
171-
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256 + " (" + Math.round((scanned / (progressThing * 256)) * 100) / 100 + "%)");
173+
scannedLabel.setText("Scanned: " + scanned);
172174
} catch (InterruptedException timeout2) {
173175
// Timed out or smth
174176
}
@@ -184,15 +186,17 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
184186
try {
185187
nextThreadAgain.join();
186188
++scanned;
187-
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256);
189+
scannedLabel.setText("Scanned: " + scanned);
188190
} catch (InterruptedException timeout1) {
189191
// Timeout, again!
190192
}
191193
}
192194

193-
frame.setVisible(false);
194-
frame.dispatchEvent(new WindowEvent(frame, 201));
195-
logger.log(Level.INFO, "Scan completed!");
195+
if(!stopping) {
196+
frame.setVisible(false);
197+
frame.dispatchEvent(new WindowEvent(frame, 201));
198+
logger.log(Level.INFO, "Scan completed!");
199+
}
196200
}
197201
}
198202

@@ -232,7 +236,7 @@ public void run() {
232236

233237
int packetId = inputStream.read();
234238

235-
if (packetId == -1 || packetId != 0xFF) {
239+
if (packetId != 0xFF) {
236240
socket.close();
237241
throw new IOException("Invalid packet: (" + packetId + ")");
238242
}
@@ -281,7 +285,7 @@ public ServerList(DatabaseHandler dbHandler) {
281285
this.dbHandler = dbHandler;
282286
this.frame = new JFrame("MCScanner - Servers (" + this.dbHandler.getServerCount() + ")");
283287
this.frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
284-
this.frame.setSize(500, 500);
288+
this.frame.setSize(720, 500);
285289
this.frame.setLayout(new BorderLayout());
286290

287291
JTable table = new JTable();
@@ -300,31 +304,20 @@ public ServerList(DatabaseHandler dbHandler) {
300304
table.setFillsViewportHeight(true);
301305
table.setRowHeight(20);
302306
table.setRowSelectionAllowed(false);
307+
table.setDefaultEditor(Object.class, null);
308+
table.setColumnSelectionAllowed(false);
309+
table.setCellSelectionEnabled(false);
303310
table.getTableHeader().setReorderingAllowed(false);
304311
table.getTableHeader().setResizingAllowed(false);
305312

306313
JScrollPane scrollPane = new JScrollPane(table);
307314
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
308315
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
309316

310-
ArrayList < Document > documents = this.dbHandler.getServers();
311-
for (Document document: documents) {
312-
String ip = document.getString("ip");
313-
String motd = document.getString("motd");
314-
String version = document.getString("version");
315-
int players = document.getInteger("maxPlayers");
316-
317-
((DefaultTableModel) table.getModel()).addRow(new Object[] {
318-
ip, motd, version, players
319-
});
320-
}
321-
322-
JButton refreshButton = new JButton("Refresh");
323-
324-
refreshButton.addActionListener(e -> {
317+
Timer timer = new Timer(10000, e -> {
325318
((DefaultTableModel) table.getModel()).setRowCount(0);
326-
327319
ArrayList < Document > documents1 = this.dbHandler.getServers();
320+
this.frame.setTitle("MCScanner - Servers (" + documents1.size() + ")");
328321
for (Document document: documents1) {
329322
String ip = document.getString("ip");
330323
String motd = document.getString("motd");
@@ -336,12 +329,28 @@ public ServerList(DatabaseHandler dbHandler) {
336329
});
337330
}
338331
});
332+
timer.setRepeats(true);
333+
timer.start();
334+
timer.getListeners(ActionListener.class)[0].actionPerformed(null);
335+
336+
// copy IP to clipboard when clicked
337+
table.addMouseListener(new java.awt.event.MouseAdapter() {
338+
@Override
339+
public void mouseClicked(java.awt.event.MouseEvent evt) {
340+
int row = table.rowAtPoint(evt.getPoint());
341+
String ip = table.getModel().getValueAt(row, 0).toString();
342+
StringSelection stringSelection = new StringSelection(ip);
343+
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
344+
clipboard.setContents(stringSelection, null);
345+
// make message box appear that saying "copied ip to clipboard"
346+
JOptionPane.showMessageDialog(null, "Copied " + ip + " to clipboard!", "Copied!", JOptionPane.INFORMATION_MESSAGE);
347+
}
348+
});
339349

340350
TableRowSorter < TableModel > sorter = new TableRowSorter < > (table.getModel());
341351
table.setRowSorter(sorter);
342352

343353
this.frame.add(scrollPane, BorderLayout.CENTER);
344-
this.frame.add(refreshButton, BorderLayout.SOUTH);
345354
}
346355

347356
public boolean toggleGUI() {

0 commit comments

Comments
 (0)