Advertisement
jonalu

alts.min.vc scraper source V2

Jan 19th, 2012
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.15 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Frame;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.io.BufferedReader;
  7. import java.io.File;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.io.PrintStream;
  12. import java.net.URL;
  13. import java.util.ArrayList;
  14. import java.util.Random;
  15.  
  16. import javax.imageio.ImageIO;
  17.  
  18.  
  19. public class Scraper {
  20.     public static void main(String[] args) {
  21.         init();
  22.         System.out.println("-=Jonalu's online alt database account scraper=-");
  23.         System.out.println("loading...");
  24.         Frame f = new Frame();
  25.         ca = new CaptchaApplet();
  26.         f.add(ca);
  27.         f.setSize(150, 100);
  28.         f.setVisible(true);
  29.         f.setAlwaysOnTop(true);
  30.         f.setBackground(Color.WHITE);
  31.         BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
  32.         ca.repaint();
  33.         String uIn;
  34.         System.out.println("type help for commands");
  35.         try {
  36.             while((uIn = stdIn.readLine()) != null) {
  37.                 command(uIn);
  38.             }
  39.         } catch (IOException e) {
  40.             e.printStackTrace();
  41.         }
  42.         exit();
  43.     }
  44.     private static void exit() {
  45.         System.out.println("-=Exiting=-");
  46.         System.exit(0);
  47.     }
  48.     private static void init() {
  49.         scrapedUsernames = new ArrayList<String>();
  50.     }
  51.  
  52.     private static void command(String uIn) {
  53.         if(uIn.equalsIgnoreCase("help")) {
  54.             showHelp();
  55.         } else if(uIn.equalsIgnoreCase("save")) {
  56.             save();
  57.         } else if(uIn.toLowerCase().startsWith("scrape")) {
  58.             scrapeCommand(uIn);
  59.         } else if(uIn.toLowerCase().startsWith("setfile")) {
  60.             setfile(uIn);
  61.         } else if(uIn.equalsIgnoreCase("exit")) {
  62.             exit();
  63.         } else if(uIn.equalsIgnoreCase("abort")) {
  64.             abortCommand(uIn);
  65.         } else if(captchaImage != null) {
  66.             captchaCode = uIn;
  67.         }
  68.     }
  69.  
  70.     private static void setfile(String uIn) {
  71.         try {
  72.             String[] as = uIn.split(" ");
  73.             if(as.length == 2) {
  74.                 outputFile = new File(as[1]);
  75.                 if(outputFile.exists() && outputFile.isDirectory())
  76.                     System.out.println("That's a directory!");
  77.                 else if(!outputFile.exists() && !outputFile.createNewFile())
  78.                     System.out.println("Couldn't create file");
  79.                 else
  80.                     System.out.println("Output file set");
  81.             } else {
  82.                 System.out.println("Syntax Error. Correct Usage: setfile <path>");
  83.             }
  84.         } catch(IOException ioe) {
  85.             ioe.printStackTrace();
  86.         }
  87.     }
  88.     private static void abortCommand(String uIn) {
  89.         abortScraping();
  90.     }
  91.     private static void scrapeCommand(String uIn) {
  92.         String[] as = uIn.split(" ");
  93.         if(as.length == 2) {
  94.             try {
  95.                 int i = Integer.parseInt(as[1]);
  96.                 scrape(i);
  97.             } catch(Exception e) {
  98.                 System.out.println("Syntax Error. Correct Usage: scrape <count>");
  99.             }
  100.         } else {
  101.             System.out.println("Syntax Error. Correct Usage: scrape <count>");
  102.         }
  103.     }
  104.     private static Thread scrapeThread = null;
  105.     private static void scrape(final int i) {
  106.         System.out.println("Scraping "+i+ (i == 1 ? " username" : " usernames"));
  107.         scrapeThread = new Thread() {
  108.             public void run() {
  109.                 try {
  110.                     for(int i1 = 0; i1 < i; i1++) {
  111.                         String s = scrape();
  112.                         if(s == null) {
  113.                             if(i1 < i-1) {
  114.                                 System.out.println("Waiting 2 minutes");
  115.                                 Thread.sleep(1000L*60L*2L);
  116.                             }
  117.                             continue;
  118.                         }
  119.                         System.out.println(s);
  120.                         break;
  121.                     }
  122.                 } catch(IOException ioe) {
  123.                     ioe.printStackTrace();
  124.                 } catch (InterruptedException e) {
  125.                 }
  126.                 System.out.println("Scraping finished.");
  127.                 showTotalUsernames();
  128.             }
  129.         };
  130.         scrapeThread.start();
  131.     }
  132.     private static void showTotalUsernames() {
  133.         System.out.println("Total Usernames: "+scrapedUsernames.size());
  134.     }
  135.     private static void abortScraping() {
  136.         if(scrapeThread != null && scrapeThread.isAlive()) {
  137.             scrapeThread.interrupt();
  138.             showTotalUsernames();
  139.         } else {
  140.             System.out.println("Not scraping.");
  141.         }
  142.     }
  143.     private static void save() {
  144.         try {
  145.             if(outputFile == null || (!outputFile.exists() && !outputFile.mkdirs() && !outputFile.createNewFile())) {
  146.                 System.out.println("no output file set. use setfile <path>.");
  147.             } else {
  148.                 BufferedReader br = new BufferedReader(new FileReader(outputFile));
  149.                 ArrayList<String> usernames = new ArrayList<String>();
  150.                
  151.                 String s1;
  152.                 while((s1 = br.readLine()) != null) {
  153.                     usernames.add(s1);
  154.                 }
  155.                 br.close();
  156.                 for(String s : scrapedUsernames) {
  157.                     if(!usernames.contains(s))
  158.                         usernames.add(s);
  159.                 }
  160.                
  161.                 PrintStream ps = new PrintStream(outputFile);
  162.                
  163.                 for(String s : usernames) {
  164.                     ps.println(s);
  165.                 }
  166.                
  167.                 ps.flush();
  168.                 ps.close();
  169.                 System.out.println("Successfully saved.");
  170.             }
  171.         } catch (IOException e) {
  172.             e.printStackTrace();
  173.         }
  174.     }
  175.  
  176.     private static void showHelp() {
  177.         System.out.println("-=Help=-");
  178.         System.out.println("scrape <count> - scrape accounts");
  179.         System.out.println("abort - abort scraping accounts");
  180.         System.out.println("save - save scraped accounts to file");
  181.         System.out.println("setfile <path> - set output file path");
  182.         System.out.println("help - show this help");
  183.         System.out.println("exit - exit the scraper");
  184.     }
  185.    
  186.     private static String scrape() throws IOException, InterruptedException {
  187.         {
  188.             String s = "http://alts.min.vc/?getalt";
  189.             captchaImage = ImageIO.read(new URL(s));
  190.             ca.repaint();
  191.             System.out.println("enter the captcha code now.");
  192.             while(captchaCode == null)
  193.                 Thread.sleep(2L);
  194.         }
  195.        
  196.         String s = "http://alts.min.vc/?getalt&captcha="+captchaCode+"&client="+getRandomString(5, 7);
  197.         captchaCode = null;
  198.         captchaImage = null;
  199.         ca.repaint();
  200.         URL url = new URL(s);
  201.         InputStreamReader isr = new InputStreamReader(url.openStream());
  202.         BufferedReader br = new BufferedReader(isr);
  203.         //String s1;
  204.         /*ArrayList<String> file = new ArrayList<String>();
  205.         String s1;
  206.         while((s1 = br.readLine()) != null) {
  207.             file.add(s1);
  208.             System.out.println(s1);
  209.         }
  210.         if(true)
  211.             return "";/**/
  212.         String[] as;
  213.         as = br.readLine().split(":");
  214.         br.close();
  215.         isr.close();
  216.         if(as.length == 2) {
  217.             if(!scrapedUsernames.contains(as[0])) {
  218.                 scrapedUsernames.add(as[0]);
  219.                 System.out.println("Scraped "+as[0]);
  220.             }
  221.             return null;
  222.         } else if(as.length > 0) {
  223.             return as[0];
  224.         } else {
  225.             return "invalid answer";
  226.         }
  227.     }
  228.    
  229.     private static File outputFile;
  230.     private static ArrayList<String> scrapedUsernames;
  231.     private static CaptchaApplet ca;
  232.     private static Image captchaImage = null;
  233.     private static String captchaCode = null;
  234.     private static Random random = new Random();
  235.    
  236.     private static final char[] allowedClientChars = new char[26];
  237.     static {
  238.         for(int i = 0; i < 26; i++)
  239.             allowedClientChars[i] = (char) ('a' + i);
  240.     }
  241.     private static String getRandomString(int minLength, int maxLength) {
  242.         int length = random.nextInt(maxLength-minLength)+minLength;
  243.         String s = "";
  244.         for(int i = 0; i < length; i++)
  245.             s += allowedClientChars[random.nextInt(allowedClientChars.length)];
  246.         return s;
  247.     }
  248.    
  249.     private static class CaptchaApplet extends Applet {
  250.         private static final long serialVersionUID = 2701017711819916677L;
  251.         public CaptchaApplet() {
  252.            
  253.         }
  254.         public void paint(Graphics g) {
  255.             if(captchaImage != null) {
  256.                 g.drawImage(captchaImage, 0, 0, this);
  257.             }
  258.         }
  259.     }
  260.    
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement