Skip to content

Commit

Permalink
v1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
StupidRepo committed Jul 17, 2023
1 parent 318126c commit d601a03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Changes
All notable changes to this project will be documented in `CHANGELOG.md`.
## Added
* A menu that allows for configuring the MongoDB URI.
<img alt="MongoDB menu screen thingy" height="50%" src="images/1_12-mongomenu.png" width="50%"/>
Nothing has been added.

## Modified
* Fixed an IllegalStateException (`IllegalStateException: state should be: open`) stopping servers from being saved to the database.
* Fixed the percentage going over 100%
* Changed thread code a little bit
* Added a "Hits" counter for successfully scanned servers

## Removed
* Removed a few unnecessary comments and debug outputs.
Nothing has been removed.
23 changes: 20 additions & 3 deletions src/com/stupidrepo/mcscanner/MCScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ public static void main(String[] var0) {
scannedLabel.setHorizontalAlignment(0);

frame.add(scannedLabel, "Center");
frame.setVisible(true);

long scanned = 0;
long hits = 0;

JLabel hitsLabel = new JLabel("Hits: 0/0");
hitsLabel.setHorizontalAlignment(0);

frame.add(hitsLabel, "South");

frame.setVisible(true);

// TODO: Make this whole thing more efficient, and less ugly.
for (int i = minimumRange; i <= maxRange; ++i) {
Expand All @@ -147,7 +154,8 @@ public static void main(String[] var0) {
for (int l = 0; l <= 255; ++l) {
String ip = i + "." + j + "." + k + "." + l;

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

Expand All @@ -156,8 +164,12 @@ public static void main(String[] var0) {
try {
nextThread.join();
++scanned;
if(scannerThread.didHit) {
++hits;
}
// progressBar.setValue(scanned);
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256 + " (" + Math.round((scanned / progressThing * 256) * 100) / 100 + "%)");
hitsLabel.setText("Hits: " + hits + "/" + scanned);
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256 + " (" + Math.round((scanned / (progressThing * 256)) * 100) / 100 + "%)");
} catch (InterruptedException timeout2) {
// eh
}
Expand All @@ -174,6 +186,7 @@ public static void main(String[] var0) {
nextThreadAgain.join();
++scanned;
// progressBar.setValue(scanned);
hitsLabel.setText("Hits: " + hits + "/" + scanned);
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing * 256);
} catch (InterruptedException timeout1) {
// well
Expand All @@ -192,6 +205,8 @@ class ScannerThread implements Runnable {
private final int timeout;
private final DatabaseHandler dbHandler;

public boolean didHit = false;

public ScannerThread(String ip, int port, int timeout, DatabaseHandler dbHandler) {
this.ip = ip;
this.port = port;
Expand Down Expand Up @@ -267,6 +282,8 @@ public void run() {
}

socket.close();

didHit = true;
} catch (IOException var8) {
// No response/invalid response/timeout/port accidentally left open
}
Expand Down

0 comments on commit d601a03

Please sign in to comment.