Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.uk.norres;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Vector;
- /**
- * LB35 Turniers | lift-on 12.11.2019 | for MikkoSyrjala0N TurnySyrjalaN
- *
- * by SHANNAN Syrjala (at) lesbians (at) UNIX(TM) with D2LD0s UX
- */
- public class Main {
- protected Vector<Job> jobs = new Vector<Job>();
- protected void addJob(Job job) {
- synchronized (jobs) {
- jobs.addElement(job);
- jobs.notify();
- }
- }
- protected Job getNextJob() {
- while (jobs.size() <= 0) {
- synchronized (jobs) {
- try {
- jobs.wait();
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- }
- synchronized (jobs) {
- Job job = jobs.elementAt(0);
- jobs.removeElementAt(0);
- return job;
- }
- }
- protected interface Job {
- public void proceed();
- public String getAddress();
- public void setAddress(String s);
- }
- public class JobImpl implements Job {
- private String ipAddress;
- public void proceed() {
- }
- public String getAddress() {
- return this.ipAddress;
- }
- public void setAddress(String s) {
- this.ipAddress = s;
- }
- }
- private class Worker implements Runnable {
- protected int id;
- public void begin(int id) {
- this.id = id;
- Thread t = new Thread(this);
- t.start();
- }
- public void run() {
- while (true) {
- //LB35Log(("worker[" + this.id + "]"));
- Job job = getNextJob();
- //LB35Log("<- PROCEED" + new java.util.Date() + ": lb35 address/lift-on " + job.getAddress());
- job.proceed();
- }
- }
- }
- private static void LB35Log(String msg) {
- System.out.println("" + msg);
- }
- public static void main(String[] args) throws IOException {
- Main m = new Main();
- if (args!= null && args.length > 0) {
- m.doit(args[0]);
- } else {
- m.doit(null);
- }
- }
- private void doit(String mode) {
- LB35Log("!!!! mode ["+mode+"]");
- if ((mode == null || mode.equalsIgnoreCase("")) || !(mode.equalsIgnoreCase("all") || mode.equalsIgnoreCase("127")
- || mode.equalsIgnoreCase("all") || mode.equalsIgnoreCase("127") || mode.equalsIgnoreCase("192")
- || mode.equalsIgnoreCase("10") || mode.equalsIgnoreCase("172") || mode.equalsIgnoreCase("0"))) {
- throw new IllegalStateException("invalid mode");
- }
- for (int i = 0; i < 100; i++) {
- Worker w = new Worker();
- w.begin((i + 1));
- }
- if (mode.equalsIgnoreCase("127") || mode.equalsIgnoreCase("all")) {
- doitImpl2(127,0,0,2,
- -2,-2,0,1);
- } if (mode.equalsIgnoreCase("192") || mode.equalsIgnoreCase("all")) {
- doitImpl(192,168,0,0,
- -2,-2,0,0);
- } if (mode.equalsIgnoreCase("10") || mode.equalsIgnoreCase("all")) {
- doitImpl(10,0,1,0,
- -2,-2,1,0);
- } if (mode.equalsIgnoreCase("172") || mode.equalsIgnoreCase("all")) {
- doitImpl(172,16,0,0,
- -2,-2,0,0);
- } if (mode.equalsIgnoreCase("0") || mode.equalsIgnoreCase("all")) {
- doitImpl(0,0,0,0,
- -2,-2,0,0);
- }
- }
- private void doitImpl2(int a0, int b0, int c0, int d0,
- int a00, int b00, int c00, int d00) {
- final int fa = a0;
- final int fb = b0;
- final int fc = c0;
- final int fd = d0;
- String address = fa + "." + fb + "." + fc + "." + fd;
- for (int i = 0; i < 10; i++) {
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- while (true) {
- impl(getAddress(),false);
- impl(getAddress(),false);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- }
- for (int i = 0; i < 10; i++) {
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- while (true) {
- impl("127.0.0.1", false);
- impl("127.0.0.1", false);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- }
- for (int i = 0; i < 10; i++) {
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- while (true) {
- impl(getAddress(),true);
- impl(getAddress(),true);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- }
- for (int i = 0; i < 10; i++) {
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- while (true) {
- impl("127.0.0.1", true);
- impl("127.0.0.1", true);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- }
- }
- private void doitImpl(int a0, int b0, int c0, int d0,
- int a00, int b00, int c00, int d00) {
- boolean a0b = true;
- boolean b0b = true;
- boolean c0b = true;
- boolean d0b = true;
- if (a00 > -1) {
- a0b = false;
- }
- if (b00 > -1) {
- b0b = false;
- }
- if (c00 > -1) {
- c0b = false;
- }
- if (d00 > -1) {
- d0b = false;
- }
- int limitA = 255;
- if (a00 == -2) {
- limitA = a0;
- }
- int limitB = 255;
- if (b00 == -2) {
- limitB = b0;
- }
- for (int a = a0; a <= limitA; a++) {
- if (!a0b) {
- a0b = true;
- a = a00;
- }
- for (int b = b0; b <= limitB; b++) {
- if (!b0b) {
- b0b = true;
- b = b00;
- }
- for (int c = c0; c <= 255; c++) {
- if (!c0b) {
- c0b = true;
- c = c00;
- }
- for (int d = d0; d <= 255; d++) {
- if (!d0b) {
- d0b = true;
- d = d00;
- }
- final int fa = a;
- final int fb = b;
- final int fc = c;
- final int fd = d;
- String address = fa + "." + fb + "." + fc + "." + fd;
- //LB35Log(" -> NEW " + new java.util.Date() + ": lb35 address/lift-on " + address);
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- impl(getAddress(), false);
- impl(getAddress(), false);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- Job job2 = new JobImpl() {
- @Override
- public void proceed() {
- try {
- impl(getAddress(), true);
- impl(getAddress(), true);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job2.setAddress(address);
- addJob(job2);
- }
- }
- }
- }
- }
- private void impl(final String address, boolean personal) throws Exception {
- LB35Log("-> doin' [\033[1;31m" + address + "\033[0m] [\033[0;34m]" + new java.util.Date() + "\033[0m]");
- String[] args = new String[2];
- if (!personal) {
- args[0] = "/Users/shannansyrjala/norres-app/doit.pl";
- } else {
- args[0] = "/Users/shannansyrjala/norres-app/doit2.pl";
- }
- args[1] = address;
- Process p = Runtime.getRuntime().exec(args);
- Thread th = new Thread() {
- public void run() {
- try {
- final InputStream is = p.getInputStream();
- final OutputStream os = p.getOutputStream();
- try {
- int n = -1;
- byte[] buffer = new byte[4096];
- ByteArrayOutputStream norobots_bytes = new ByteArrayOutputStream();
- while ((n = is.read(buffer, 0, buffer.length)) != -1) {
- norobots_bytes.write(buffer, 0, n);
- }
- LB35Log("" + new String(norobots_bytes.toByteArray(), "UTF-8"));
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- os.close();
- is.close();
- p.waitFor();
- LB35Log("<- DONE [\033[1;31m" + address + "\033[0m] [\033[0;34m]" + new java.util.Date() + "\033[0m]");
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- th.start();
- try {
- p.waitFor();
- synchronized (th) {
- th.join();
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement