Skip to content

Commit

Permalink
v1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
StupidRepo committed Jul 19, 2023
1 parent 0481917 commit a56ade3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ All notable changes to this project will be documented in `CHANGELOG.md`.
Nothing has been added.

## Modified
* Fixed scanner setting `offset.mcscan` to 255.255.255.255
* Stopping & resuming handling.

## Removed
* Debug prints
Nothing has been removed.

## TODOs
- [ ] Optimise IP generation and inital scanning code.[¹][1]
Expand Down
4 changes: 0 additions & 4 deletions offset.mcscan

This file was deleted.

59 changes: 41 additions & 18 deletions src/com/stupidrepo/mcscanner/MCScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class MCScanner {
private static int offsetJ = 0;
private static int offsetK = 0;
private static int offsetL = 0;
private static boolean stopping = false;

public static void main(String[] var0) {
AtomicInteger threads = new AtomicInteger(1024);
int timeout = 1000;
Expand Down Expand Up @@ -72,17 +74,22 @@ public static void main(String[] var0) {
frame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
stopping = true;
logger.log(Level.INFO, "Stopping threads...");
for (Thread nextThread: threadList) {
nextThread.interrupt();
try {
nextThread.join();
} catch (InterruptedException timeouter) {
// Timeout or something idk
}
}
logger.log(Level.INFO, "Making an 'offset.mcscan'...");
logger.log(Level.INFO, "Making an '.resumescan'...");
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("offset.mcscan"));
BufferedWriter writer = new BufferedWriter(new FileWriter(".resumescan"));
writer.write(String.valueOf(offsetI + "\n" + offsetJ + "\n" + offsetK + "\n" + offsetL));
writer.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to write 'offset.mcscan'!");
logger.log(Level.SEVERE, "Failed to write '.resumescan'!");
}
logger.log(Level.INFO, "Exiting...");
System.exit(0);
Expand All @@ -105,10 +112,10 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {

frame.setVisible(true);

File offsetFile = new File("offset.mcscan");
File offsetFile = new File(".resumescan");
if (offsetFile.exists()) {
try {
logger.log(Level.INFO, "Found 'offset.mcscan'!");
logger.log(Level.INFO, "Found '.resumescan'!");
BufferedReader reader = new BufferedReader(new FileReader(offsetFile));
offsetI = Integer.parseInt(reader.readLine());
offsetJ = Integer.parseInt(reader.readLine());
Expand All @@ -117,7 +124,7 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
logger.log(Level.INFO, "Continuing from " + offsetI + "." + offsetJ + "." + offsetK + "." + offsetL + "...");
reader.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to read 'offset.mcscan'!");
logger.log(Level.SEVERE, "Failed to read '.resumescan'!");
}
}

Expand All @@ -126,26 +133,42 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
int thisOffsetK = offsetK;
int thisOffsetL = offsetL;
for (int i = thisOffsetI; i <= maxRange; ++i) {
offsetI = i;
if(stopping) {
break;
} else {
offsetI = i;
}
for (int j = thisOffsetJ; j <= 255; ++j) {
offsetJ = j;
if(stopping) {
break;
} else {
offsetJ = j;
}
for (int k = thisOffsetK; k <= 255; ++k) {
offsetK = k;
if(stopping) {
break;
} else {
offsetK = k;
}
for (int l = thisOffsetL; l <= 255; ++l) {
offsetL = l;
String ip = i + "." + j + "." + k + "." + l;

ScannerThread scannerThread = new ScannerThread(ip, port, timeout, databaseHandler);
Thread scanThread = new Thread(scannerThread);
threadList.add(scanThread);
scanThread.start();
if(stopping) {
break;
} else {
offsetL = l;
String ip = i + "." + j + "." + k + "." + l;

ScannerThread scannerThread = new ScannerThread(ip, port, timeout, databaseHandler);
Thread scanThread = new Thread(scannerThread);
threadList.add(scanThread);
scanThread.start();
}

if (threadList.size() >= threads.get()) {
for (Thread nextThread: threadList) {
try {
nextThread.join();
++scanned;
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256 + " (" + Math.round((scanned / (progressThing * 256)) * 100) / 100 + "%) (" + ip + ")");
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256 + " (" + Math.round((scanned / (progressThing * 256)) * 100) / 100 + "%)");
} catch (InterruptedException timeout2) {
// Timed out or smth
}
Expand Down

0 comments on commit a56ade3

Please sign in to comment.