Advertisement
Guest User

ifs 0.1

a guest
Jan 11th, 2013
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package ifs;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.Random;
  9.  
  10. public class IFS {
  11.    
  12.     private static final int THREADS = 10;
  13.  
  14.     private static class MyRunnable implements Runnable {
  15.        
  16.         private static final String STR_MESSAGE = "(%d) %s";
  17.         private static final String STR_SUCCESS = "(%d) %d/%d=%f %s";
  18.        
  19.         private final int mThreadId;
  20.         private int mSuccess = 0;
  21.         private int mTotal = 0;
  22.        
  23.         public MyRunnable(int id){
  24.             mThreadId = id;
  25.         }
  26.  
  27.         @Override
  28.         public void run() {
  29.             final Random random = new Random();
  30.             boolean found = false;
  31.             while (true) {
  32.                 String chars = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
  33.                 String s = generateString(random, chars, 6);
  34.                 final String url = "http://files.icq.net/files/get?fileId="+ s;
  35.                 try {
  36.                     found = false;
  37.                     URL u = new URL(url);
  38.                     mTotal++;
  39.                     URLConnection uc = u.openConnection();
  40.                     uc.connect();
  41.                     uc.getContent();
  42.                     found = true;
  43.                     mSuccess++;
  44.                 } catch (MalformedURLException e) {
  45.                     System.out.println(String.format(STR_MESSAGE, mThreadId, e.getMessage()));
  46.                 } catch (FileNotFoundException e) {
  47.  
  48.                 } catch (IOException e) {
  49.                     System.out.println(String.format(STR_MESSAGE, mThreadId, e.getMessage()));
  50.                 }
  51.                 if(found){
  52.                     final double p = mSuccess / mTotal;
  53.                     System.out.println(String.format(STR_SUCCESS, mThreadId, mSuccess, mTotal, p, url));
  54.                 }
  55.             }
  56.         }
  57.  
  58.     }
  59.  
  60.     /**
  61.      * @param args
  62.      */
  63.     public static void main(String[] args) {
  64.         System.out.println("ICQ Files Scanner 0.1");
  65.         for(int i=0; i<THREADS; i++){
  66.             new Thread(new MyRunnable(i)).start();         
  67.         }
  68.     }
  69.  
  70.     public static String generateString(Random rng, String characters,
  71.             int length) {
  72.         char[] text = new char[length];
  73.         for (int i = 0; i < length; i++) {
  74.             text[i] = characters.charAt(rng.nextInt(characters.length()));
  75.         }
  76.         return new String(text);
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement