Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.uk.norres;
- import co.uk.norres.Main.Job;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Vector;
- /**
- * LB35 Turniers | lift-on 11.3.2019 | for MikkoSyrjala0N TurnySyrjala0N
- */
- public class Main {
- protected Vector<Job> jobs = new Vector<Job>();
- protected void addJob(Job job) {
- //LB35Log("addJob");
- synchronized (jobs) {
- jobs.addElement(job);
- jobs.notify();
- }
- }
- protected Job getNextJob() {
- //LB35Log("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();
- m.doit();
- }
- private void doit() {
- for (int i = 0; i < 50; i++) {
- Worker w = new Worker();
- w.begin((i + 1));
- }
- //0.147.72.116
- //int a0 = 0;
- //int b0 = 147;
- //int c0 = 72;
- //int d0 = 116;
- //int a0 = 192;
- //int b0 = 168;
- //int c0 = 0;
- //int d0 = 0;
- int a0 = 10;
- int b0 = 0;
- int c0 = 0;
- int d0 = 0;
- boolean a0b = false;
- boolean b0b = false;
- boolean c0b = false;
- boolean d0b = false;
- int a = a0;
- //int b = b0;
- //for (int a = a0; a <= 255; a++) {
- /*
- if (!a0b) {
- a0b = true;
- a = a0;
- }
- */
- for (int b = b0; b <= 255; b++) {
- /*
- if (!b0b) {
- b0b = true;
- b = b0;
- }
- */
- for (int c = c0; c <= 255; c++) {
- /*
- if (!c0b) {
- c0b = true;
- c = c0;
- }
- */
- for (int d = d0; d <= 255; d++) {
- /*
- if (!d0b) {
- d0b = true;
- d = d0;
- */
- //String address = a + "." + b + "." + c + "." + d;
- //LB35Log(" -> NEW " + new java.util.Date() + ": lb35 address/lift-on " + ipAddress);
- final int fa = a;
- final int fb = b;
- final int fc = c;
- final int fd = d;
- String address = fa + "." + fb + "." + fc + "." + fd;
- Job job = new JobImpl() {
- @Override
- public void proceed() {
- try {
- impl(getAddress());
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- job.setAddress(address);
- addJob(job);
- }
- }
- }
- }
- private void impl(final String address) throws Exception {
- LB35Log("<- doin' " + new java.util.Date() + ": lb35 address/lift-on " + address);
- String[] args = new String[2];
- args[0] = "/home/shannansyrjala/doit.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();
- }
- os.close();
- is.close();
- //p.waitFor();
- //LB35Log("<- DONE " + new java.util.Date() + ": lb35 address/lift-on " + ipAddress + "\n");
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- };
- th.start();
- try {
- //p.waitFor();
- Thread.currentThread().sleep(2000);
- p.destroyForcibly();
- p.destroy();
- //th.stop();
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement