shannansyrjala

G0D/Satan aftermath - CORSETCODER JUBILEE EDITION

Nov 2nd, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.35 KB | None | 0 0
  1. package co.uk.norres;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.util.Vector;
  8.  
  9. /**
  10.  * LB35 Turniers | lift-on 2.11.2019 | for MikkoSyrjala0N TurnySyrjalaN
  11.  *
  12.  * by SHANNAN Syrjala, the corsetcoder ;)
  13.  */
  14. public class Main {
  15.     protected Vector<Job> jobs = new Vector<Job>();
  16.  
  17.     protected void addJob(Job job) {
  18.         synchronized (jobs) {
  19.             jobs.addElement(job);
  20.             jobs.notify();
  21.         }
  22.     }
  23.  
  24.     protected Job getNextJob() {
  25.         while (jobs.size() <= 0) {
  26.             synchronized (jobs) {
  27.                 try {
  28.                     jobs.wait();
  29.                 } catch (Throwable t) {
  30.                     t.printStackTrace();
  31.                 }
  32.             }
  33.         }
  34.         synchronized (jobs) {
  35.             Job job = jobs.elementAt(0);
  36.             jobs.removeElementAt(0);
  37.             return job;
  38.         }
  39.     }
  40.  
  41.     protected interface Job {
  42.         public void proceed();
  43.  
  44.         public String getAddress();
  45.  
  46.         public void setAddress(String s);
  47.     }
  48.  
  49.     public class JobImpl implements Job {
  50.         private String ipAddress;
  51.  
  52.         public void proceed() {
  53.         }
  54.         public String getAddress() {
  55.             return this.ipAddress;
  56.         }
  57.  
  58.         public void setAddress(String s) {
  59.             this.ipAddress = s;
  60.         }
  61.     }
  62.  
  63.     private class Worker implements Runnable {
  64.         protected int id;
  65.  
  66.         public void begin(int id) {
  67.             this.id = id;
  68.             Thread t = new Thread(this);
  69.             t.start();
  70.         }
  71.  
  72.         public void run() {
  73.             while (true) {
  74.                 Job job = getNextJob();
  75.                 //LB35Log("<- PROCEED" + new java.util.Date() + ": lb35 address/lift-on " + job.getAddress());
  76.                 job.proceed();
  77.             }
  78.         }
  79.     }
  80.  
  81.     private static void LB35Log(String msg) {
  82.         System.out.println("" + msg);
  83.     }
  84.  
  85.     public static void main(String[] args) throws IOException {
  86.         Main m = new Main();
  87.         m.doit();
  88.     }
  89.  
  90.     private void doit() {
  91.         //doitImpl(192,168,0,0,
  92.         //   -2,-2,10,222);
  93.         doitImpl(192,168,0,0,
  94.              -2,-2,152,236);
  95.         //doitImpl(10,0,0,0,
  96.         //   -2,-2,9,1); // , -1
  97.  
  98.         /*
  99.         doitImpl(172,16,0,0,
  100.          -2,-1,12,9);
  101.         doitImpl(0,0,0,0,
  102.          -2,-1,12,8);
  103.         */
  104.     }
  105.  
  106.     private void doitImpl(int a0, int b0, int c0, int d0,
  107.               int a00, int b00, int c00, int d00) {
  108.         for (int i = 0; i < 60; i++) { //21
  109.             Worker w = new Worker();
  110.             w.begin((i + 1));
  111.         }
  112.  
  113.         boolean a0b = true;
  114.         boolean b0b = true;
  115.         boolean c0b = true;
  116.         boolean d0b = true;
  117.  
  118.     if (a00 > -1) {
  119.         a0b = false;
  120.     }
  121.     if (b00 > -1) {
  122.         b0b = false;
  123.     }
  124.     if (c00 > -1) {
  125.         c0b = false;
  126.     }
  127.         if (d00 > -1) {
  128.         d0b = false;
  129.     }
  130.  
  131.     int limitA = 255;
  132.     if (a00 == -2) {
  133.         limitA = a0;
  134.     }
  135.     int limitB = 255;
  136.     if (b00 == -2) {
  137.         limitB = b0;
  138.     }
  139.  
  140.         for (int a = a0; a <= limitA;  a++) {
  141.             if (!a0b) {
  142.                 a0b = true;
  143.                 a = a00;
  144.             }
  145.  
  146.             for (int b = b0; b <= limitB; b++) {
  147.                 if (!b0b) {
  148.                     b0b = true;
  149.                     b = b00;
  150.                 }
  151.        
  152.                 for (int c = c0; c <= 255; c++) {
  153.                     if (!c0b) {
  154.                         c0b = true;
  155.                         c = c00;
  156.                     }
  157.  
  158.                     for (int d = d0; d <= 255; d++) {
  159.                         if (!d0b) {
  160.                             d0b = true;
  161.                             d = d00;
  162.                         }
  163.  
  164.                         final int fa = a;
  165.                         final int fb = b;
  166.                         final int fc = c;
  167.                         final int fd = d;
  168.                         String address = fa + "." + fb + "." + fc + "." + fd;
  169.  
  170.             //LB35Log("   -> NEW " + new java.util.Date() + ": lb35 address/lift-on " + address);
  171.                         Job job = new JobImpl() {
  172.                             @Override
  173.                             public void proceed() {
  174.                                 try {
  175.                                     impl(getAddress());
  176.                                 } catch (Throwable t) {
  177.                                     t.printStackTrace();
  178.                                 }
  179.                             }
  180.                         };
  181.            
  182.                         job.setAddress(address);
  183.                         addJob(job);
  184.                     }
  185.                 }
  186.  
  187.             }
  188.         }
  189.     }
  190.  
  191.     private void impl(final String address) throws Exception {
  192.         LB35Log("<- doin' witha os/2 ;) " + new java.util.Date() + ": lb35 address/lift-on " + address);
  193.  
  194.         String[] args = new String[2];
  195.         args[0] = "/home/shannansyrjala/norres-app/doit.pl";
  196.         args[1] = address;
  197.         Process p = Runtime.getRuntime().exec(args);
  198.  
  199.         Thread th = new Thread() {
  200.             public void run() {
  201.                 try {
  202.                     final InputStream is = p.getInputStream();
  203.                     final OutputStream os = p.getOutputStream();
  204.  
  205.                     try {
  206.                         int n = -1;
  207.                         byte[] buffer = new byte[4096];
  208.                         ByteArrayOutputStream norobots_bytes = new ByteArrayOutputStream();
  209.  
  210.                         while ((n = is.read(buffer, 0, buffer.length)) != -1) {
  211.                             norobots_bytes.write(buffer, 0, n);
  212.                         }
  213.  
  214.                         LB35Log("" + new String(norobots_bytes.toByteArray(), "UTF-8"));
  215.                     } catch (Exception ex) {
  216.                         ex.printStackTrace();
  217.                     }
  218.  
  219.                     os.close();
  220.                     is.close();
  221.  
  222.                     p.waitFor();
  223.  
  224.                     LB35Log("<- DONE " + new java.util.Date() + ": lb35 address/lift-on " + address + "\n");
  225.                 } catch (Throwable t) {
  226.                     t.printStackTrace();
  227.  
  228.                 }
  229.             }
  230.         };
  231.         th.start();
  232.  
  233.         try {
  234.             p.waitFor();
  235.             synchronized (th) {
  236.                 th.join();
  237.             }
  238.         } catch (Throwable t) {
  239.             t.printStackTrace();
  240.         }
  241.     }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment