Created
January 8, 2020 07:25
-
-
Save 0xdeki/5039c4e98766c86955ab16b124c920d1 to your computer and use it in GitHub Desktop.
Spawn tons of fake LAN servers for minecraft =]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.deki.lanbomb; | |
import java.net.SocketException; | |
/** | |
* @author Endre on 08.01.2020 | |
* @project mc | |
**/ | |
public class LanBomb { | |
public static void main(String[] args) throws SocketException { | |
for (int i = 0; i < 10; i++) new LanBombThread().start(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.deki.lanbomb; | |
import java.io.IOException; | |
import java.net.*; | |
import java.nio.charset.Charset; | |
import java.nio.charset.StandardCharsets; | |
import java.util.Random; | |
/** | |
* @author Endre on 08.01.2020 | |
* @project mcp 1.12 | |
**/ | |
public class LanBombThread extends Thread { | |
private final String motd; | |
private final DatagramSocket socket; | |
private final int port; | |
private boolean isStopping = false; | |
public LanBombThread() throws SocketException { | |
byte[] array = new byte[64]; | |
new Random().nextBytes(array); | |
this.motd = new String(array, Charset.forName("UTF-8")); | |
this.port = getRandomPort(); | |
this.socket = new DatagramSocket(); | |
} | |
public void run() { | |
while (!this.isInterrupted() && !this.isStopping) { | |
try { | |
byte[] payload = generatePing().getBytes(StandardCharsets.UTF_8); | |
InetAddress address = InetAddress.getByName("224.0.2.60"); | |
DatagramPacket datagrampacket = new DatagramPacket(payload, payload.length, address, 4445); | |
this.socket.send(datagrampacket); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
break; | |
} | |
try { | |
sleep(1500L); | |
} catch (InterruptedException e) { | |
} | |
} | |
} | |
private String generatePing() { | |
return "[MOTD]" + this.motd + "[/MOTD][AD]" + this.port + "[/AD]"; | |
} | |
private int getRandomPort() { | |
int i = -1; | |
try { | |
ServerSocket serversocket = new ServerSocket(0); | |
i = serversocket.getLocalPort(); | |
serversocket.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
if (i <= 0) { | |
i = 25564; | |
} | |
return i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment